-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathplan-builder.js
More file actions
231 lines (217 loc) · 9.88 KB
/
plan-builder.js
File metadata and controls
231 lines (217 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
'use strict';
const types = require('./server-types-generated.js');
const bldrbase = require('./plan-builder-base.js');
const bldrgen = require('./plan-builder-generated.js');
/** @ignore */
function isNonEmptyString(arg) {
if (typeof arg === 'string' || arg instanceof String) {
return (arg.length > 0);
}
return false;
}
/** @ignore */
function iriMaker(builder, prefix, name) {
if (!isNonEmptyString(name)) {
throw new Error('cannot define '+prefix+' iri without name: '+name);
}
const lastChar = prefix.substr(-1, 1);
const firstChar = name.substr(0, 1);
if (firstChar === lastChar) {
if (name.length === 1) {
throw new Error('cannot define '+prefix+' iri with name of '+name);
}
// TODO: name separator should override prefix separator in SJS, XQY, and Java
name = name.substr(1);
} else if (name.length === 0) {
throw new Error('cannot define '+prefix+' iri with empty name');
}
return builder.sem.iri(prefix + name);
}
bldrgen.AccessPlan.prototype.col = function(...args) {
const self = this;
const paramdef = ['column', [types.XsString], true, false];
const checkedArgs = bldrbase.makeSingleArgs('PlanAccessPlan.col', 1, paramdef, args);
const colName = checkedArgs[0];
const accessorArgs = self._args;
switch (self._fn) {
case 'from-lexicons':
case 'from-literals':
case 'from-triples':
const qualifierName = (accessorArgs.length > 1) ? accessorArgs[1] : null;
if (qualifierName !== void 0 && qualifierName !== null) {
return new bldrgen.PlanColumn('op', 'view-col', [qualifierName, colName]);
}
break;
case 'from-view':
const viewQualifier = (accessorArgs.length > 2) ? accessorArgs[2] : null;
if (viewQualifier !== void 0 && viewQualifier !== null) {
return new bldrgen.PlanColumn('op', 'view-col', [viewQualifier, colName]);
} else {
const schemaName = accessorArgs[0];
const viewName = accessorArgs[1];
return new bldrgen.PlanColumn('op', 'schema-col',
[((schemaName === void 0) ? null : schemaName), viewName, colName]
);
}
break;
}
return new bldrgen.PlanColumn('op', 'col', checkedArgs);
};
bldrgen.CtsExpr.prototype.param = function(...args) {
const paramdef = ['name', [types.XsString], true, false];
const checkedArgs = bldrbase.makeSingleArgs('cts.param', 1, paramdef, args);
return new types.CtsParam('cts', 'param', checkedArgs);
};
class Builder extends bldrgen.PlanBuilder {
constructor() {
super({});
if(this.rdt === void 0) {
this.rdt = new RdtExpr();
}
}
prefixer(base) {
const self = this;
if (!isNonEmptyString(base)) {
throw new Error('cannot define prefixer without prefix: '+base);
}
const lastChar = base.substr(-1, 1);
if (lastChar !== '/' && lastChar !== '#' && lastChar !== '?') {
base += '/';
}
const prefix = base;
return function(name) {
return iriMaker(self, prefix, name);
};
}
resolveFunction(functionName, modulePath) {
return super.resolveFunction(
(functionName instanceof types.XsQName) ? functionName : this.xs.QName(functionName),
modulePath
);
}
}
class RdtExpr {
constructor() {
}
/**
* This function replaces values with masking text that is deterministic. A given input generates the same mask value every time it is applied.
* Controls features such as the length and type of the generated value.
* @method planBuilder#maskDeterministic
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
maskDeterministic(...args) {
return redactimpl('maskDeterministic', 'mask-deterministic',1,args);
}
/** This function replaces values with random text. The masking value can vary across repeated application to the same input value.
* Controls the length of the generated value and type of replacement text (numbers or letters).
* @method planBuilder#maskRandom
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
maskRandom(...args) {
return redactimpl('maskRandom', 'mask-random', 1, args);
}
/** This function redacts data that matches the pattern of a dateTime value. Controls the expected input format and the masking dateTime format.
* @method planBuilder#redactDatetime
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
redactDatetime(...args) {
return redactimpl('redactDatetime', 'redact-datetime',2, args);
}
/** This function redacts data that matches the pattern of an email address.
* Controls whether to mask the entire address, only the username, or only the domain name.
* @method planBuilder#redactEmail
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
redactEmail(...args) {
return redactimpl('redactEmail', 'redact-email', 1, args);
}
/** This function redacts data that matches the pattern of an IPv4 address. Controls what character to use as a masking character.
* @method planBuilder#redactIpv4
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
redactIpv4(...args) {
return redactimpl('redactIpv4', 'redact-ipv4', 1, args);
}
/** This function replaces values with random numbers. Controls the data type, range, and format of the masking values.
* @method planBuilder#redactNumber
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
redactNumber(...args) {
return redactimpl('redactNumber', 'redact-number', 1, args);
}
/** This function redacts data that matches a given regular expression. You must specify the regular expression and the masking text.
* @method planBuilder#redactRegex
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
redactRegex(...args) {
return redactimpl('redactRegex', 'redact-regex', 2, args);
}
/** This function redacts data that matches the pattern of a US Social Security Number (SSN).
* Controls whether or not to preserve the last 4 digits and what character to use as a masking character.
* @method planBuilder#redactUsSsn
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
redactUsSsn(...args) {
return redactimpl('redactUsSsn', 'redact-us-ssn', 1, args);
}
/** This function redacts data that matches the pattern of a US telephone number.
* Controls whether or not to preserve the last 4 digits and what character to use as a masking character.
* @method planBuilder#redactUsPhone
* @since 2.7.0
* @param args - with column and options - Column is the name of the column to be defined.
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
* Options is an object with name-value pairs specific to the redaction method.
* @returns { planBuilder.PlanExprCol }
*/
redactUsPhone(...args) {
return redactimpl('redactUsPhone', 'redact-us-phone', 1, args);
}
}
function redactimpl(clientName, serverName, minArity, args) {
const namer = bldrbase.getNamer(args, 'column');
const paramdefs = [['column', [bldrgen.PlanColumn, types.XsString], true, false], ['option', [], false, false]];
const checkedArgs = (namer !== null) ?
bldrbase.makeNamedArgs(namer, `PlanBuilder.${clientName}`, minArity, new Set(['column', 'options']), paramdefs, args) :
bldrbase.makePositionalArgs(`PlanBuilder.${clientName}`, minArity, false, paramdefs, args);
return new bldrgen.PlanExprCol('ordt', serverName, checkedArgs);
}
const builder = new Builder();
module.exports = {
builder: builder,
Plan: bldrgen.Plan
};