@servicenow/sdk-build-core 3.0.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +25 -0
- package/dist/app.js +8 -0
- package/dist/app.js.map +1 -0
- package/dist/compiler.d.ts +60 -0
- package/dist/compiler.js +320 -0
- package/dist/compiler.js.map +1 -0
- package/dist/compression.d.ts +7 -0
- package/dist/compression.js +79 -0
- package/dist/compression.js.map +1 -0
- package/dist/crypto.d.ts +1 -0
- package/dist/crypto.js +9 -0
- package/dist/crypto.js.map +1 -0
- package/dist/diagnostic.d.ts +41 -0
- package/dist/diagnostic.js +130 -0
- package/dist/diagnostic.js.map +1 -0
- package/dist/{plugins/Diagnostic.d.ts → fluent-diagnostic.d.ts} +3 -2
- package/dist/fluent-diagnostic.js +23 -0
- package/dist/fluent-diagnostic.js.map +1 -0
- package/dist/fluent-directive.d.ts +8 -0
- package/dist/fluent-directive.js +54 -0
- package/dist/fluent-directive.js.map +1 -0
- package/dist/fluent-file.d.ts +5 -0
- package/dist/fluent-file.js +15 -0
- package/dist/fluent-file.js.map +1 -0
- package/dist/formatter.d.ts +11 -0
- package/dist/formatter.js +77 -0
- package/dist/formatter.js.map +1 -0
- package/dist/fs.d.ts +174 -0
- package/dist/fs.js +313 -0
- package/dist/fs.js.map +1 -0
- package/dist/guid.d.ts +2 -0
- package/dist/{GUID.js → guid.js} +3 -6
- package/dist/guid.js.map +1 -0
- package/dist/index.d.ts +19 -5
- package/dist/index.js +19 -5
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +5 -0
- package/dist/json.js +43 -0
- package/dist/json.js.map +1 -0
- package/dist/keys-registry.d.ts +64 -0
- package/dist/keys-registry.js +339 -0
- package/dist/keys-registry.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +17 -0
- package/dist/logger.js.map +1 -0
- package/dist/now-config.d.ts +348 -0
- package/dist/now-config.js +283 -0
- package/dist/now-config.js.map +1 -0
- package/dist/path.d.ts +3 -0
- package/dist/path.js +12 -0
- package/dist/path.js.map +1 -0
- package/dist/plugins/cache.d.ts +20 -0
- package/dist/plugins/cache.js +46 -0
- package/dist/plugins/cache.js.map +1 -0
- package/dist/plugins/context.d.ts +85 -0
- package/dist/plugins/{Context.js → context.js} +1 -1
- package/dist/plugins/context.js.map +1 -0
- package/dist/plugins/database.d.ts +27 -0
- package/dist/plugins/database.js +102 -0
- package/dist/plugins/database.js.map +1 -0
- package/dist/plugins/file.d.ts +10 -0
- package/dist/plugins/{behaviors/Arranger.js → file.js} +1 -1
- package/dist/plugins/file.js.map +1 -0
- package/dist/plugins/index.d.ts +9 -5
- package/dist/plugins/index.js +9 -6
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/plugin.d.ts +478 -0
- package/dist/plugins/plugin.js +533 -0
- package/dist/plugins/plugin.js.map +1 -0
- package/dist/plugins/product.d.ts +15 -0
- package/dist/plugins/product.js +38 -0
- package/dist/plugins/product.js.map +1 -0
- package/dist/plugins/project.d.ts +25 -0
- package/dist/plugins/{behaviors/Generator.js → project.js} +1 -1
- package/dist/plugins/project.js.map +1 -0
- package/dist/plugins/shape.d.ts +424 -0
- package/dist/plugins/shape.js +1181 -0
- package/dist/plugins/shape.js.map +1 -0
- package/dist/plugins/time.d.ts +12 -0
- package/dist/plugins/time.js +84 -0
- package/dist/plugins/time.js.map +1 -0
- package/dist/plugins/usage.d.ts +11 -0
- package/dist/plugins/usage.js +26 -0
- package/dist/plugins/usage.js.map +1 -0
- package/dist/prettier/config-loader.d.ts +13 -0
- package/dist/prettier/config-loader.js +105 -0
- package/dist/prettier/config-loader.js.map +1 -0
- package/dist/telemetry/index.d.ts +25 -0
- package/dist/telemetry/index.js +18 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/typescript.d.ts +293 -0
- package/dist/typescript.js +454 -0
- package/dist/typescript.js.map +1 -0
- package/dist/util/get-file-type.d.ts +2 -0
- package/dist/util/get-file-type.js +13 -0
- package/dist/util/get-file-type.js.map +1 -0
- package/dist/util/index.d.ts +2 -6
- package/dist/util/index.js +2 -6
- package/dist/util/index.js.map +1 -1
- package/dist/util/{Scope.js → is-sn-scope.js} +1 -1
- package/dist/util/is-sn-scope.js.map +1 -0
- package/dist/xml.d.ts +24 -0
- package/dist/xml.js +71 -0
- package/dist/xml.js.map +1 -0
- package/now.config.schema.json +336 -0
- package/package.json +22 -12
- package/src/app.ts +33 -0
- package/src/compiler.ts +384 -0
- package/src/compression.ts +93 -0
- package/src/crypto.ts +5 -0
- package/src/diagnostic.ts +108 -0
- package/src/{plugins/Diagnostic.ts → fluent-diagnostic.ts} +3 -10
- package/src/fluent-directive.ts +63 -0
- package/src/fluent-file.ts +13 -0
- package/src/formatter.ts +58 -0
- package/src/fs.ts +438 -0
- package/src/{GUID.ts → guid.ts} +2 -6
- package/src/index.ts +19 -5
- package/src/json.ts +20 -0
- package/src/keys-registry.ts +384 -0
- package/src/logger.ts +20 -0
- package/src/now-config.ts +337 -0
- package/src/path.ts +9 -0
- package/src/plugins/cache.ts +45 -0
- package/src/plugins/context.ts +93 -0
- package/src/plugins/database.ts +121 -0
- package/src/plugins/file.ts +19 -0
- package/src/plugins/index.ts +9 -5
- package/src/plugins/plugin.ts +995 -0
- package/src/plugins/product.ts +44 -0
- package/src/plugins/project.ts +39 -0
- package/src/plugins/shape.ts +1532 -0
- package/src/plugins/time.ts +108 -0
- package/src/plugins/usage.ts +26 -0
- package/src/prettier/config-loader.ts +130 -0
- package/src/telemetry/index.ts +27 -0
- package/src/typescript.ts +502 -0
- package/src/util/get-file-type.ts +11 -0
- package/src/util/index.ts +2 -6
- package/src/xml.ts +86 -0
- package/dist/GUID.d.ts +0 -2
- package/dist/GUID.js.map +0 -1
- package/dist/IncludePaths.d.ts +0 -25
- package/dist/IncludePaths.js +0 -97
- package/dist/IncludePaths.js.map +0 -1
- package/dist/Keys.d.ts +0 -32
- package/dist/Keys.js +0 -245
- package/dist/Keys.js.map +0 -1
- package/dist/TypeScript.d.ts +0 -5
- package/dist/TypeScript.js +0 -58
- package/dist/TypeScript.js.map +0 -1
- package/dist/XML.d.ts +0 -32
- package/dist/XML.js +0 -83
- package/dist/XML.js.map +0 -1
- package/dist/plugins/Context.d.ts +0 -190
- package/dist/plugins/Context.js.map +0 -1
- package/dist/plugins/Diagnostic.js +0 -28
- package/dist/plugins/Diagnostic.js.map +0 -1
- package/dist/plugins/Plugin.d.ts +0 -175
- package/dist/plugins/Plugin.js +0 -15
- package/dist/plugins/Plugin.js.map +0 -1
- package/dist/plugins/behaviors/Arranger.d.ts +0 -26
- package/dist/plugins/behaviors/Arranger.js.map +0 -1
- package/dist/plugins/behaviors/Composer.d.ts +0 -102
- package/dist/plugins/behaviors/Composer.js +0 -15
- package/dist/plugins/behaviors/Composer.js.map +0 -1
- package/dist/plugins/behaviors/Diagnostics.d.ts +0 -7
- package/dist/plugins/behaviors/Diagnostics.js +0 -3
- package/dist/plugins/behaviors/Diagnostics.js.map +0 -1
- package/dist/plugins/behaviors/Generator.d.ts +0 -21
- package/dist/plugins/behaviors/Generator.js.map +0 -1
- package/dist/plugins/behaviors/OwnedTables.d.ts +0 -6
- package/dist/plugins/behaviors/OwnedTables.js +0 -3
- package/dist/plugins/behaviors/OwnedTables.js.map +0 -1
- package/dist/plugins/behaviors/PostProcessor.d.ts +0 -5
- package/dist/plugins/behaviors/PostProcessor.js +0 -3
- package/dist/plugins/behaviors/PostProcessor.js.map +0 -1
- package/dist/plugins/behaviors/Serializer.d.ts +0 -30
- package/dist/plugins/behaviors/Serializer.js +0 -3
- package/dist/plugins/behaviors/Serializer.js.map +0 -1
- package/dist/plugins/behaviors/Transformer.d.ts +0 -23
- package/dist/plugins/behaviors/Transformer.js +0 -3
- package/dist/plugins/behaviors/Transformer.js.map +0 -1
- package/dist/plugins/behaviors/extractors/Data.d.ts +0 -119
- package/dist/plugins/behaviors/extractors/Data.js +0 -244
- package/dist/plugins/behaviors/extractors/Data.js.map +0 -1
- package/dist/plugins/behaviors/extractors/Extractors.d.ts +0 -63
- package/dist/plugins/behaviors/extractors/Extractors.js +0 -3
- package/dist/plugins/behaviors/extractors/Extractors.js.map +0 -1
- package/dist/plugins/behaviors/extractors/index.d.ts +0 -2
- package/dist/plugins/behaviors/extractors/index.js +0 -19
- package/dist/plugins/behaviors/extractors/index.js.map +0 -1
- package/dist/plugins/behaviors/index.d.ts +0 -9
- package/dist/plugins/behaviors/index.js +0 -26
- package/dist/plugins/behaviors/index.js.map +0 -1
- package/dist/plugins/util/CallExpression.d.ts +0 -5
- package/dist/plugins/util/CallExpression.js +0 -88
- package/dist/plugins/util/CallExpression.js.map +0 -1
- package/dist/plugins/util/CodeTransformation.d.ts +0 -95
- package/dist/plugins/util/CodeTransformation.js +0 -624
- package/dist/plugins/util/CodeTransformation.js.map +0 -1
- package/dist/plugins/util/ObjectLiteral.d.ts +0 -9
- package/dist/plugins/util/ObjectLiteral.js +0 -37
- package/dist/plugins/util/ObjectLiteral.js.map +0 -1
- package/dist/plugins/util/index.d.ts +0 -3
- package/dist/plugins/util/index.js +0 -20
- package/dist/plugins/util/index.js.map +0 -1
- package/dist/util/Debug.d.ts +0 -4
- package/dist/util/Debug.js +0 -20
- package/dist/util/Debug.js.map +0 -1
- package/dist/util/Directive.d.ts +0 -16
- package/dist/util/Directive.js +0 -107
- package/dist/util/Directive.js.map +0 -1
- package/dist/util/RuntimeTableSchema.d.ts +0 -5
- package/dist/util/RuntimeTableSchema.js +0 -58
- package/dist/util/RuntimeTableSchema.js.map +0 -1
- package/dist/util/Scope.js.map +0 -1
- package/dist/util/Util.d.ts +0 -1
- package/dist/util/Util.js +0 -12
- package/dist/util/Util.js.map +0 -1
- package/dist/util/XMLUploadParser.d.ts +0 -22
- package/dist/util/XMLUploadParser.js +0 -67
- package/dist/util/XMLUploadParser.js.map +0 -1
- package/src/IncludePaths.ts +0 -122
- package/src/Keys.ts +0 -274
- package/src/TypeScript.ts +0 -65
- package/src/XML.ts +0 -98
- package/src/plugins/Context.ts +0 -239
- package/src/plugins/Plugin.ts +0 -278
- package/src/plugins/behaviors/Arranger.ts +0 -42
- package/src/plugins/behaviors/Composer.ts +0 -125
- package/src/plugins/behaviors/Diagnostics.ts +0 -12
- package/src/plugins/behaviors/Generator.ts +0 -31
- package/src/plugins/behaviors/OwnedTables.ts +0 -5
- package/src/plugins/behaviors/PostProcessor.ts +0 -6
- package/src/plugins/behaviors/Serializer.ts +0 -40
- package/src/plugins/behaviors/Transformer.ts +0 -32
- package/src/plugins/behaviors/extractors/Data.ts +0 -332
- package/src/plugins/behaviors/extractors/Extractors.ts +0 -73
- package/src/plugins/behaviors/extractors/index.ts +0 -2
- package/src/plugins/behaviors/index.ts +0 -9
- package/src/plugins/util/CallExpression.ts +0 -110
- package/src/plugins/util/CodeTransformation.ts +0 -731
- package/src/plugins/util/ObjectLiteral.ts +0 -37
- package/src/plugins/util/index.ts +0 -3
- package/src/util/Debug.ts +0 -24
- package/src/util/Directive.ts +0 -123
- package/src/util/RuntimeTableSchema.ts +0 -44
- package/src/util/Util.ts +0 -7
- package/src/util/XMLUploadParser.ts +0 -90
- /package/dist/util/{Scope.d.ts → is-sn-scope.d.ts} +0 -0
- /package/src/util/{Scope.ts → is-sn-scope.ts} +0 -0
|
@@ -0,0 +1,1181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.RecordId = exports.Record = exports.VariableStatementShape = exports.ElementAccessExpressionShape = exports.SourceFileShape = exports.CallExpressionShape = exports.ObjectShape = exports.ArrayShape = exports.BooleanShape = exports.NumberShape = exports.TaggedTemplateExpressionShape = exports.TemplateExpressionShape = exports.TemplateSpanShape = exports.StringLiteralShape = exports.StringShape = exports.PropertyAccessShape = exports.IdentifierShape = exports.ResolvableShape = exports.DeletedShape = exports.UndefinedShape = exports.UnresolvedShape = exports.NoOpShape = exports.Shape = void 0;
|
|
27
|
+
exports.getInstallCategory = getInstallCategory;
|
|
28
|
+
const product_1 = require("./product");
|
|
29
|
+
const path_1 = require("../path");
|
|
30
|
+
const typescript_1 = require("../typescript");
|
|
31
|
+
const json_1 = require("../json");
|
|
32
|
+
const _ = __importStar(require("lodash"));
|
|
33
|
+
class Shape extends product_1.Product {
|
|
34
|
+
constructor({ source }) {
|
|
35
|
+
super(source);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Instantiate an appropriate shape from the given value. If the value is already
|
|
39
|
+
* a shape, it will be returned as-is.
|
|
40
|
+
*/
|
|
41
|
+
static from(source, value) {
|
|
42
|
+
if (value instanceof Shape) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
else if (typeof value === 'string') {
|
|
46
|
+
return new StringLiteralShape({ source, literalText: value });
|
|
47
|
+
}
|
|
48
|
+
else if (typeof value === 'number') {
|
|
49
|
+
return new NumberShape({ source, value });
|
|
50
|
+
}
|
|
51
|
+
else if (typeof value === 'boolean') {
|
|
52
|
+
return new BooleanShape({ source, value });
|
|
53
|
+
}
|
|
54
|
+
else if (value === undefined || value === null) {
|
|
55
|
+
return new UndefinedShape({ source });
|
|
56
|
+
}
|
|
57
|
+
else if (Array.isArray(value)) {
|
|
58
|
+
return new ArrayShape({ source, elements: value });
|
|
59
|
+
}
|
|
60
|
+
else if (typeof value === 'object') {
|
|
61
|
+
return new ObjectShape({ source, properties: value });
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error(`Tried to create shape from invalid value (type: ${typeof value}): ${json_1.JSON5.stringify(value)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Instantiate a NoOpShape which has no value and will not generate or update
|
|
69
|
+
* any code. Useful for shapes that are not supported for bidirectional sync.
|
|
70
|
+
*/
|
|
71
|
+
static noOp(source) {
|
|
72
|
+
return new NoOpShape(source);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets the value of the shape.
|
|
76
|
+
*/
|
|
77
|
+
getValue() {
|
|
78
|
+
return Symbol(this.getKind());
|
|
79
|
+
}
|
|
80
|
+
equals(value) {
|
|
81
|
+
value = value instanceof Shape ? value.getValue() : value;
|
|
82
|
+
return value === this.getValue();
|
|
83
|
+
}
|
|
84
|
+
pipe(pipeFn) {
|
|
85
|
+
return pipeFn(this);
|
|
86
|
+
}
|
|
87
|
+
isResolvable() {
|
|
88
|
+
return this.is(ResolvableShape);
|
|
89
|
+
}
|
|
90
|
+
isIdentifier() {
|
|
91
|
+
return this.is(IdentifierShape);
|
|
92
|
+
}
|
|
93
|
+
isString() {
|
|
94
|
+
return this.is(StringShape);
|
|
95
|
+
}
|
|
96
|
+
isStringLiteral() {
|
|
97
|
+
return this.is(StringLiteralShape);
|
|
98
|
+
}
|
|
99
|
+
isNumber() {
|
|
100
|
+
return this.is(NumberShape);
|
|
101
|
+
}
|
|
102
|
+
isBoolean() {
|
|
103
|
+
return this.is(BooleanShape);
|
|
104
|
+
}
|
|
105
|
+
isNoOp() {
|
|
106
|
+
return this.is(NoOpShape);
|
|
107
|
+
}
|
|
108
|
+
isUnresolved() {
|
|
109
|
+
return this.is(UnresolvedShape);
|
|
110
|
+
}
|
|
111
|
+
isUndefined() {
|
|
112
|
+
return this.is(UndefinedShape);
|
|
113
|
+
}
|
|
114
|
+
isDefined() {
|
|
115
|
+
return !this.isUndefined() && !this.isUnresolved() && !this.isNoOp();
|
|
116
|
+
}
|
|
117
|
+
isArray() {
|
|
118
|
+
return this.is(ArrayShape);
|
|
119
|
+
}
|
|
120
|
+
isObject() {
|
|
121
|
+
return this.is(ObjectShape);
|
|
122
|
+
}
|
|
123
|
+
isRecord() {
|
|
124
|
+
return this.is(Record);
|
|
125
|
+
}
|
|
126
|
+
isRecordId() {
|
|
127
|
+
return this.is(RecordId);
|
|
128
|
+
}
|
|
129
|
+
is(shapeClass) {
|
|
130
|
+
for (const c of Array.isArray(shapeClass) ? shapeClass : [shapeClass]) {
|
|
131
|
+
if (this instanceof c) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
ifResolvable() {
|
|
138
|
+
return this.if(ResolvableShape);
|
|
139
|
+
}
|
|
140
|
+
ifIdentifier() {
|
|
141
|
+
return this.if(IdentifierShape);
|
|
142
|
+
}
|
|
143
|
+
ifString() {
|
|
144
|
+
return this.if(StringShape);
|
|
145
|
+
}
|
|
146
|
+
ifStringLiteral() {
|
|
147
|
+
return this.if(StringLiteralShape);
|
|
148
|
+
}
|
|
149
|
+
ifNumber() {
|
|
150
|
+
return this.if(NumberShape);
|
|
151
|
+
}
|
|
152
|
+
ifBoolean() {
|
|
153
|
+
return this.if(BooleanShape);
|
|
154
|
+
}
|
|
155
|
+
ifUnresolved() {
|
|
156
|
+
return this.if(UnresolvedShape);
|
|
157
|
+
}
|
|
158
|
+
ifUndefined() {
|
|
159
|
+
return this.if(UndefinedShape);
|
|
160
|
+
}
|
|
161
|
+
ifDefined() {
|
|
162
|
+
return this.isDefined() ? this : undefined;
|
|
163
|
+
}
|
|
164
|
+
ifArray() {
|
|
165
|
+
return this.if(ArrayShape);
|
|
166
|
+
}
|
|
167
|
+
ifObject() {
|
|
168
|
+
return this.if(ObjectShape);
|
|
169
|
+
}
|
|
170
|
+
ifRecord() {
|
|
171
|
+
return this.if(Record);
|
|
172
|
+
}
|
|
173
|
+
ifRecordId() {
|
|
174
|
+
return this.if(RecordId);
|
|
175
|
+
}
|
|
176
|
+
if(shapeClass) {
|
|
177
|
+
return this.is(shapeClass) ? this : undefined;
|
|
178
|
+
}
|
|
179
|
+
asResolvable(failureMessage) {
|
|
180
|
+
return this.as(ResolvableShape, failureMessage);
|
|
181
|
+
}
|
|
182
|
+
asIdentifier(failureMessage) {
|
|
183
|
+
return this.as(IdentifierShape, failureMessage);
|
|
184
|
+
}
|
|
185
|
+
asString(failureMessage) {
|
|
186
|
+
return this.as(StringShape, failureMessage);
|
|
187
|
+
}
|
|
188
|
+
asStringLiteral(failureMessage) {
|
|
189
|
+
return this.as(StringLiteralShape, failureMessage);
|
|
190
|
+
}
|
|
191
|
+
asNumber(failureMessage) {
|
|
192
|
+
return this.as(NumberShape, failureMessage);
|
|
193
|
+
}
|
|
194
|
+
asBoolean(failureMessage) {
|
|
195
|
+
return this.as(BooleanShape, failureMessage);
|
|
196
|
+
}
|
|
197
|
+
asUnresolved(failureMessage) {
|
|
198
|
+
return this.as(UnresolvedShape, failureMessage);
|
|
199
|
+
}
|
|
200
|
+
asUndefined(failureMessage) {
|
|
201
|
+
return this.as(UndefinedShape, failureMessage);
|
|
202
|
+
}
|
|
203
|
+
asArray(failureMessage) {
|
|
204
|
+
return this.as(ArrayShape, failureMessage);
|
|
205
|
+
}
|
|
206
|
+
asObject(failureMessage) {
|
|
207
|
+
return this.as(ObjectShape, failureMessage);
|
|
208
|
+
}
|
|
209
|
+
asRecord(failureMessage) {
|
|
210
|
+
return this.as(Record, failureMessage);
|
|
211
|
+
}
|
|
212
|
+
asRecordId(failureMessage) {
|
|
213
|
+
return this.as(RecordId, failureMessage);
|
|
214
|
+
}
|
|
215
|
+
as(shapeClass, failureMessage) {
|
|
216
|
+
for (const c of Array.isArray(shapeClass) ? shapeClass : [shapeClass]) {
|
|
217
|
+
if (this.is(c)) {
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
throw new Error(failureMessage ??
|
|
222
|
+
`Failed to cast ${this.getKind()} to ${Array.isArray(shapeClass) ? `any of the requested shapes: ${shapeClass.map((c) => c.name).join(', ')}` : shapeClass.name}`);
|
|
223
|
+
}
|
|
224
|
+
toString() {
|
|
225
|
+
if (this.isString()) {
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
return Shape.from(this, String(this.getValue())).asString();
|
|
229
|
+
}
|
|
230
|
+
toNumber() {
|
|
231
|
+
if (this.isNumber()) {
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
const value = this.getValue();
|
|
235
|
+
const coerced = Number(value);
|
|
236
|
+
//check for empty string since Number('') returns 0
|
|
237
|
+
if (isNaN(coerced) || (typeof value === 'string' && !value.trim())) {
|
|
238
|
+
throw new Error(`Cannot coerce value to number: ${value}`);
|
|
239
|
+
}
|
|
240
|
+
return new NumberShape({ source: this.getSource(), value: coerced });
|
|
241
|
+
}
|
|
242
|
+
toBoolean() {
|
|
243
|
+
if (this.isBoolean()) {
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
const value = this.getValue();
|
|
247
|
+
if (typeof value !== 'boolean') {
|
|
248
|
+
throw new Error(`Cannot coerce value to boolean: ${value}`);
|
|
249
|
+
}
|
|
250
|
+
return new BooleanShape({ source: this, value });
|
|
251
|
+
}
|
|
252
|
+
toRecordId() {
|
|
253
|
+
if (this.isRecordId()) {
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
throw new Error(`Coercion from ${this.getKind()} to record ID is not supported`);
|
|
257
|
+
}
|
|
258
|
+
getKind() {
|
|
259
|
+
return this.constructor.name;
|
|
260
|
+
}
|
|
261
|
+
getDescription() {
|
|
262
|
+
return this.getKind();
|
|
263
|
+
}
|
|
264
|
+
getCode() {
|
|
265
|
+
const value = this.getValue();
|
|
266
|
+
if (typeof value === 'symbol') {
|
|
267
|
+
throw new Error(`Shape's value is a symbol which is not supported by the default code generation behavior: ${this.getDescription()}`);
|
|
268
|
+
}
|
|
269
|
+
return json_1.JSON5.stringify(this.getValue(), { space: 1, quote: "'" });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.Shape = Shape;
|
|
273
|
+
class NoOpShape extends Shape {
|
|
274
|
+
constructor(source) {
|
|
275
|
+
super({ source });
|
|
276
|
+
}
|
|
277
|
+
getValue() {
|
|
278
|
+
throw new Error('Cannot get a value from a no-op shape');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.NoOpShape = NoOpShape;
|
|
282
|
+
class UnresolvedShape extends Shape {
|
|
283
|
+
static CODE = 'Now.UNRESOLVED';
|
|
284
|
+
static VALUE = Symbol(UnresolvedShape.CODE);
|
|
285
|
+
getValue() {
|
|
286
|
+
return UnresolvedShape.VALUE;
|
|
287
|
+
}
|
|
288
|
+
getCode() {
|
|
289
|
+
return UnresolvedShape.CODE;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exports.UnresolvedShape = UnresolvedShape;
|
|
293
|
+
class UndefinedShape extends Shape {
|
|
294
|
+
constructor({ source }) {
|
|
295
|
+
super({ source });
|
|
296
|
+
}
|
|
297
|
+
getValue() {
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
equals(other) {
|
|
301
|
+
return Shape.from(this, other).isUndefined();
|
|
302
|
+
}
|
|
303
|
+
toString() {
|
|
304
|
+
return Shape.from(this, '').asString();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.UndefinedShape = UndefinedShape;
|
|
308
|
+
class DeletedShape extends UndefinedShape {
|
|
309
|
+
}
|
|
310
|
+
exports.DeletedShape = DeletedShape;
|
|
311
|
+
class ResolvableShape extends Shape {
|
|
312
|
+
equals(other) {
|
|
313
|
+
return this.resolve(true).equals(other);
|
|
314
|
+
}
|
|
315
|
+
getValue() {
|
|
316
|
+
return this.resolve(true).getValue();
|
|
317
|
+
}
|
|
318
|
+
toString() {
|
|
319
|
+
return this.resolve(true).toString();
|
|
320
|
+
}
|
|
321
|
+
toNumber() {
|
|
322
|
+
return this.resolve(true).toNumber();
|
|
323
|
+
}
|
|
324
|
+
toBoolean() {
|
|
325
|
+
return this.resolve(true).toBoolean();
|
|
326
|
+
}
|
|
327
|
+
toRecordId() {
|
|
328
|
+
return this.resolve(true).toRecordId();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
exports.ResolvableShape = ResolvableShape;
|
|
332
|
+
class IdentifierShape extends ResolvableShape {
|
|
333
|
+
name;
|
|
334
|
+
value;
|
|
335
|
+
constructor({ source, name, value = new UnresolvedShape({ source }), }) {
|
|
336
|
+
super({ source });
|
|
337
|
+
this.name = name;
|
|
338
|
+
this.value = Shape.from(source, value);
|
|
339
|
+
}
|
|
340
|
+
getName() {
|
|
341
|
+
return this.name;
|
|
342
|
+
}
|
|
343
|
+
resolve(deep = true) {
|
|
344
|
+
return deep && this.value.isResolvable() ? this.value.resolve(true) : this.value;
|
|
345
|
+
}
|
|
346
|
+
getCode() {
|
|
347
|
+
return this.getName();
|
|
348
|
+
}
|
|
349
|
+
equals(other) {
|
|
350
|
+
return other instanceof IdentifierShape ? this.name === other.name && super.equals(other) : super.equals(other);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
exports.IdentifierShape = IdentifierShape;
|
|
354
|
+
class PropertyAccessShape extends ResolvableShape {
|
|
355
|
+
elements;
|
|
356
|
+
constructor({ source, elements }) {
|
|
357
|
+
super({ source });
|
|
358
|
+
this.elements = elements.map((e) => typeof e === 'string' ? new IdentifierShape({ source, name: e }) : Shape.from(source, e).asIdentifier()); // Annoying cast needed because `map()` doesn't respect tuples
|
|
359
|
+
}
|
|
360
|
+
getElements() {
|
|
361
|
+
return this.elements;
|
|
362
|
+
}
|
|
363
|
+
getElement(index) {
|
|
364
|
+
const element = this.elements[index];
|
|
365
|
+
if (!element) {
|
|
366
|
+
throw new Error(`Property access shape does not have an element at index ${index}: ${this.getCode()}`);
|
|
367
|
+
}
|
|
368
|
+
return element;
|
|
369
|
+
}
|
|
370
|
+
getFirstElement() {
|
|
371
|
+
return this.getElement(0);
|
|
372
|
+
}
|
|
373
|
+
getLastElement() {
|
|
374
|
+
return this.getElement(this.elements.length - 1);
|
|
375
|
+
}
|
|
376
|
+
resolve(deep = true) {
|
|
377
|
+
return this.getLastElement().resolve(deep);
|
|
378
|
+
}
|
|
379
|
+
getCode() {
|
|
380
|
+
return this.elements.map((e) => e.getCode()).join('.');
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
exports.PropertyAccessShape = PropertyAccessShape;
|
|
384
|
+
class StringShape extends Shape {
|
|
385
|
+
contentType = 'plain';
|
|
386
|
+
startsWith(substring) {
|
|
387
|
+
return this.getValue().startsWith(substring);
|
|
388
|
+
}
|
|
389
|
+
endsWith(substring) {
|
|
390
|
+
return this.getValue().endsWith(substring);
|
|
391
|
+
}
|
|
392
|
+
includes(substring) {
|
|
393
|
+
return this.getValue().includes(substring);
|
|
394
|
+
}
|
|
395
|
+
split(separator) {
|
|
396
|
+
return this.getValue().split(separator);
|
|
397
|
+
}
|
|
398
|
+
isEmpty() {
|
|
399
|
+
return this.getValue().length === 0;
|
|
400
|
+
}
|
|
401
|
+
ifNotEmpty() {
|
|
402
|
+
return this.isEmpty() ? undefined : this;
|
|
403
|
+
}
|
|
404
|
+
replace(regex, replacement) {
|
|
405
|
+
return Shape.from(this, this.getValue().replace(regex, replacement)).asString();
|
|
406
|
+
}
|
|
407
|
+
replaceAll(regex, replacement) {
|
|
408
|
+
return Shape.from(this, this.getValue().replaceAll(regex, replacement)).asString();
|
|
409
|
+
}
|
|
410
|
+
parseJson() {
|
|
411
|
+
const value = this.getValue();
|
|
412
|
+
const result = json_1.JSON5.parse(value);
|
|
413
|
+
if (!result || (!Array.isArray(result) && typeof result !== 'object')) {
|
|
414
|
+
throw new Error(`Failed to parse string shape as JSON: ${value}`);
|
|
415
|
+
}
|
|
416
|
+
return Shape.from(this, result).as([
|
|
417
|
+
// I have absolutely no idea why these casts are needed in this file and
|
|
418
|
+
// nowhere else. Seems like a probable TypeScript bug.
|
|
419
|
+
ObjectShape,
|
|
420
|
+
ArrayShape,
|
|
421
|
+
]);
|
|
422
|
+
}
|
|
423
|
+
withContentType(contentType) {
|
|
424
|
+
this.contentType = contentType;
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
getContentType() {
|
|
428
|
+
return this.contentType;
|
|
429
|
+
}
|
|
430
|
+
toBoolean() {
|
|
431
|
+
const value = this.getValue();
|
|
432
|
+
const trimmed = value.trim().toLowerCase();
|
|
433
|
+
if (trimmed === '') {
|
|
434
|
+
return new BooleanShape({ source: this, value: false });
|
|
435
|
+
}
|
|
436
|
+
if (!/^(true|false)$/.test(trimmed)) {
|
|
437
|
+
throw new Error(`Cannot coerce string "${value}" to boolean`);
|
|
438
|
+
}
|
|
439
|
+
return new BooleanShape({ source: this, value: trimmed === 'true' });
|
|
440
|
+
}
|
|
441
|
+
static escapeSingleQuotes(str) {
|
|
442
|
+
return str.replaceAll("'", "\\'");
|
|
443
|
+
}
|
|
444
|
+
static escapeBackticks(str) {
|
|
445
|
+
return str.replace(/[`\\]|\${/g, (char) => {
|
|
446
|
+
switch (char) {
|
|
447
|
+
case '`':
|
|
448
|
+
return '\\`';
|
|
449
|
+
case '\\':
|
|
450
|
+
return '\\' + char;
|
|
451
|
+
case '${':
|
|
452
|
+
return '\\${';
|
|
453
|
+
default:
|
|
454
|
+
return char;
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
static escapeCdataTags(str) {
|
|
459
|
+
return str.replace(/]]>/g, ']]]]><![CDATA[>');
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
exports.StringShape = StringShape;
|
|
463
|
+
class StringLiteralShape extends StringShape {
|
|
464
|
+
literalText;
|
|
465
|
+
constructor({ source, literalText }) {
|
|
466
|
+
super({ source });
|
|
467
|
+
this.literalText = typeof literalText === 'string' ? literalText : literalText.toString().getValue();
|
|
468
|
+
}
|
|
469
|
+
getValue() {
|
|
470
|
+
return this.literalText;
|
|
471
|
+
}
|
|
472
|
+
getCode() {
|
|
473
|
+
return this.includes('\n')
|
|
474
|
+
? `\`${StringShape.escapeBackticks(this.literalText)}\``
|
|
475
|
+
: `'${StringShape.escapeSingleQuotes(this.literalText)}'`;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
exports.StringLiteralShape = StringLiteralShape;
|
|
479
|
+
class TemplateSpanShape extends StringShape {
|
|
480
|
+
literalText;
|
|
481
|
+
expression;
|
|
482
|
+
constructor({ source, literalText, expression, }) {
|
|
483
|
+
super({ source });
|
|
484
|
+
this.literalText = Shape.from(source, literalText).asString().getValue();
|
|
485
|
+
this.expression = expression;
|
|
486
|
+
}
|
|
487
|
+
getLiteralText() {
|
|
488
|
+
return this.literalText;
|
|
489
|
+
}
|
|
490
|
+
getExpression() {
|
|
491
|
+
return this.expression;
|
|
492
|
+
}
|
|
493
|
+
getValue(substitution) {
|
|
494
|
+
return `${substitution instanceof Shape ? substitution.getValue() : typeof substitution === 'function' ? substitution(this.expression) : (substitution ?? this.expression.toString().getValue())}${this.literalText}`;
|
|
495
|
+
}
|
|
496
|
+
getCode() {
|
|
497
|
+
return `$\{${this.expression.getCode()}}${StringShape.escapeBackticks(this.literalText)}`;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
exports.TemplateSpanShape = TemplateSpanShape;
|
|
501
|
+
class TemplateExpressionShape extends StringShape {
|
|
502
|
+
literalText;
|
|
503
|
+
spans;
|
|
504
|
+
constructor({ source, literalText, spans, }) {
|
|
505
|
+
super({ source });
|
|
506
|
+
this.literalText = Shape.from(source, literalText).asString().getValue();
|
|
507
|
+
this.spans = spans ?? [];
|
|
508
|
+
}
|
|
509
|
+
getLiteralText() {
|
|
510
|
+
return this.literalText;
|
|
511
|
+
}
|
|
512
|
+
hasSubstitution() {
|
|
513
|
+
return this.spans.length > 0;
|
|
514
|
+
}
|
|
515
|
+
getSpans() {
|
|
516
|
+
return this.spans;
|
|
517
|
+
}
|
|
518
|
+
getValue(substitutions) {
|
|
519
|
+
return `${this.literalText}${this.spans.map((s, i) => s.getValue(typeof substitutions === 'function' ? substitutions : substitutions?.[i])).join('')}`;
|
|
520
|
+
}
|
|
521
|
+
getCode() {
|
|
522
|
+
return `\`${StringShape.escapeBackticks(this.literalText)}${this.spans.map((s) => s.getCode()).join('')}\``;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
exports.TemplateExpressionShape = TemplateExpressionShape;
|
|
526
|
+
class TaggedTemplateExpressionShape extends StringShape {
|
|
527
|
+
tag;
|
|
528
|
+
template;
|
|
529
|
+
constructor({ source, tag, template }) {
|
|
530
|
+
super({ source });
|
|
531
|
+
this.tag = Shape.from(source, tag).asString().getValue();
|
|
532
|
+
this.template = template.as(TemplateExpressionShape, 'Template must be a template expression shape');
|
|
533
|
+
}
|
|
534
|
+
getTag() {
|
|
535
|
+
return this.tag;
|
|
536
|
+
}
|
|
537
|
+
getTemplate() {
|
|
538
|
+
return this.template;
|
|
539
|
+
}
|
|
540
|
+
getValue(substitutions) {
|
|
541
|
+
return this.template.getValue(substitutions);
|
|
542
|
+
}
|
|
543
|
+
getCode() {
|
|
544
|
+
return `${this.tag || ''}${this.template.getCode()}`;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
exports.TaggedTemplateExpressionShape = TaggedTemplateExpressionShape;
|
|
548
|
+
class NumberShape extends Shape {
|
|
549
|
+
value;
|
|
550
|
+
constructor({ source, value }) {
|
|
551
|
+
super({ source });
|
|
552
|
+
this.value = value;
|
|
553
|
+
}
|
|
554
|
+
getValue() {
|
|
555
|
+
return this.value;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
exports.NumberShape = NumberShape;
|
|
559
|
+
class BooleanShape extends Shape {
|
|
560
|
+
value;
|
|
561
|
+
constructor({ source, value }) {
|
|
562
|
+
super({ source });
|
|
563
|
+
this.value = value;
|
|
564
|
+
}
|
|
565
|
+
getValue() {
|
|
566
|
+
return this.value;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
exports.BooleanShape = BooleanShape;
|
|
570
|
+
class ArrayShape extends Shape {
|
|
571
|
+
elements;
|
|
572
|
+
constructor({ source, elements }) {
|
|
573
|
+
super({ source });
|
|
574
|
+
this.elements = elements.map((e) => Shape.from(source, e));
|
|
575
|
+
}
|
|
576
|
+
getValue() {
|
|
577
|
+
return this.elements.map((e) => e.getValue());
|
|
578
|
+
}
|
|
579
|
+
getElements(resolve = true) {
|
|
580
|
+
return resolve ? this.elements.map((s) => (s.isResolvable() ? s.resolve(true) : s)) : this.elements;
|
|
581
|
+
}
|
|
582
|
+
getElement(index, resolve = true) {
|
|
583
|
+
return this.getElements(resolve)[index] ?? new UndefinedShape({ source: this });
|
|
584
|
+
}
|
|
585
|
+
hasElement(index) {
|
|
586
|
+
return index < this.elements.length;
|
|
587
|
+
}
|
|
588
|
+
map(mapFunction, resolve = true) {
|
|
589
|
+
return this.getElements(resolve).map(mapFunction);
|
|
590
|
+
}
|
|
591
|
+
equals(other) {
|
|
592
|
+
const otherShape = Shape.from(this, other);
|
|
593
|
+
if (!otherShape.isArray() || this.elements.length !== otherShape.elements.length) {
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
for (const [i, element] of this.elements.entries()) {
|
|
597
|
+
if (!element.equals(otherShape.getElement(i))) {
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
static from(source, value) {
|
|
604
|
+
if (value instanceof ArrayShape) {
|
|
605
|
+
return value;
|
|
606
|
+
}
|
|
607
|
+
value = value instanceof Shape ? value.getValue() : value;
|
|
608
|
+
const coerced = Array.isArray(value) ? value : [value];
|
|
609
|
+
return new ArrayShape({ source, elements: coerced });
|
|
610
|
+
}
|
|
611
|
+
getCode() {
|
|
612
|
+
return `[${this.map((e) => e.getCode(), false).join(', ')}]`;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
exports.ArrayShape = ArrayShape;
|
|
616
|
+
const MERGE = Symbol('MERGE');
|
|
617
|
+
const coerceTo = (coerceToType, value) => {
|
|
618
|
+
switch (coerceToType) {
|
|
619
|
+
case 'string':
|
|
620
|
+
return value.toString();
|
|
621
|
+
case 'number':
|
|
622
|
+
return value.toNumber();
|
|
623
|
+
case 'cdata':
|
|
624
|
+
return value.toString().withContentType('cdata');
|
|
625
|
+
default:
|
|
626
|
+
return value.toBoolean();
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
class Transform {
|
|
630
|
+
shape;
|
|
631
|
+
resolve;
|
|
632
|
+
_from;
|
|
633
|
+
_map;
|
|
634
|
+
_def;
|
|
635
|
+
_coerce;
|
|
636
|
+
constructor(shape, resolve = true, _from = undefined, _map = undefined, _def = undefined, _coerce = undefined) {
|
|
637
|
+
this.shape = shape;
|
|
638
|
+
this.resolve = resolve;
|
|
639
|
+
this._from = _from;
|
|
640
|
+
this._map = _map;
|
|
641
|
+
this._def = _def;
|
|
642
|
+
this._coerce = _coerce;
|
|
643
|
+
}
|
|
644
|
+
_(to) {
|
|
645
|
+
const args = (this._from ?? (to === MERGE ? [] : [to])).map((p) => this.shape.get(p, this.resolve));
|
|
646
|
+
const val = (() => {
|
|
647
|
+
if (this._map) {
|
|
648
|
+
return this._map(...args);
|
|
649
|
+
}
|
|
650
|
+
else if (this._from) {
|
|
651
|
+
return this._from.length === 1
|
|
652
|
+
? this.shape.get(this._from[0], this.resolve)
|
|
653
|
+
: this.shape.pick(this._from, { resolve: this.resolve });
|
|
654
|
+
}
|
|
655
|
+
else if (to !== MERGE) {
|
|
656
|
+
return this.shape.get(to, this.resolve);
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
return this.shape.properties({ resolve: this.resolve });
|
|
660
|
+
}
|
|
661
|
+
})();
|
|
662
|
+
if (!this._coerce) {
|
|
663
|
+
return {
|
|
664
|
+
def: this._def,
|
|
665
|
+
val,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
const valShape = Shape.from(this.shape, val);
|
|
670
|
+
return {
|
|
671
|
+
def: this._def,
|
|
672
|
+
val: valShape.ifUndefined() ?? coerceTo(this._coerce, valShape),
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
from(...properties) {
|
|
677
|
+
return new Transform(this.shape, this.resolve, properties, this._map, this._def, this._coerce);
|
|
678
|
+
}
|
|
679
|
+
map(mapFunction) {
|
|
680
|
+
return new Transform(this.shape, this.resolve, this._from, mapFunction, this._def, this._coerce);
|
|
681
|
+
}
|
|
682
|
+
val(value) {
|
|
683
|
+
return new Transform(this.shape, this.resolve, this._from, () => value, this._def, this._coerce);
|
|
684
|
+
}
|
|
685
|
+
def(value) {
|
|
686
|
+
return new Transform(this.shape, this.resolve, this._from, this._map, value, this._coerce);
|
|
687
|
+
}
|
|
688
|
+
toCdata() {
|
|
689
|
+
return new Transform(this.shape, this.resolve, this._from, this._map, this._def, 'cdata');
|
|
690
|
+
}
|
|
691
|
+
toString() {
|
|
692
|
+
return new Transform(this.shape, this.resolve, this._from, this._map, this._def, 'string');
|
|
693
|
+
}
|
|
694
|
+
toNumber() {
|
|
695
|
+
return new Transform(this.shape, this.resolve, this._from, this._map, this._def, 'number');
|
|
696
|
+
}
|
|
697
|
+
toBoolean() {
|
|
698
|
+
return new Transform(this.shape, this.resolve, this._from, this._map, this._def, 'boolean');
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
function assignWithoutOverwriting(target, source) {
|
|
702
|
+
if (!source) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
for (const [k, v] of Object.entries(source)) {
|
|
706
|
+
if (!(k in target)) {
|
|
707
|
+
target[k] = v;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
class ObjectShape extends Shape {
|
|
712
|
+
setProperties;
|
|
713
|
+
defaultProperties;
|
|
714
|
+
aliasedKeys;
|
|
715
|
+
constructor({ source, properties }) {
|
|
716
|
+
super({ source });
|
|
717
|
+
if (properties instanceof ObjectShape) {
|
|
718
|
+
this.defaultProperties = properties.defaultProperties;
|
|
719
|
+
this.setProperties = properties.setProperties;
|
|
720
|
+
this.aliasedKeys = properties.aliasedKeys;
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
this.defaultProperties = {};
|
|
724
|
+
this.aliasedKeys = {};
|
|
725
|
+
this.setProperties = Object.fromEntries(Object.entries(properties).map(([k, v]) => [k, Shape.from(source, v)]));
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
withAliasedKeys(aliasedKeys) {
|
|
729
|
+
this.aliasedKeys = aliasedKeys;
|
|
730
|
+
return this;
|
|
731
|
+
}
|
|
732
|
+
getAliasedKeys() {
|
|
733
|
+
return this.aliasedKeys;
|
|
734
|
+
}
|
|
735
|
+
findAliasUsed(key) {
|
|
736
|
+
const aliases = this.getAliases(key);
|
|
737
|
+
const properties = this.properties({ resolve: false });
|
|
738
|
+
return aliases.find((alias) => properties[alias]);
|
|
739
|
+
}
|
|
740
|
+
getAliases(key) {
|
|
741
|
+
return this.aliasedKeys[key] ?? [];
|
|
742
|
+
}
|
|
743
|
+
properties({ nonDefaultsOnly = false, resolve = true, } = {}) {
|
|
744
|
+
if (nonDefaultsOnly) {
|
|
745
|
+
const entries = Object.entries(this.setProperties).filter(([k, v]) => v.isDefined() && !v.equals(this.getDefault(k)));
|
|
746
|
+
return Object.fromEntries(resolve ? entries.map(([k, v]) => [k, v.isResolvable() ? v.resolve() : v]) : entries);
|
|
747
|
+
}
|
|
748
|
+
// This logic may seem odd, but it's written this way to preserve the ordering of
|
|
749
|
+
// the set properties instead of using the ordering of the defaults.
|
|
750
|
+
const entries = [
|
|
751
|
+
...Object.entries(this.setProperties),
|
|
752
|
+
...Object.entries(this.defaultProperties).filter(([k]) => !this.setProperties[k] || this.setProperties[k].isUndefined()),
|
|
753
|
+
];
|
|
754
|
+
return Object.fromEntries(resolve ? entries.map(([k, v]) => [k, v.isResolvable() ? v.resolve() : v]) : entries);
|
|
755
|
+
}
|
|
756
|
+
getValue(nonDefaultsOnly = false) {
|
|
757
|
+
return Object.fromEntries(this.entries({ nonDefaultsOnly }).map(([k, v]) => [k, v.getValue()]));
|
|
758
|
+
}
|
|
759
|
+
get(propertyOrPath, resolve = true) {
|
|
760
|
+
const [property, next, ...rest] = typeof propertyOrPath === 'string' ? [propertyOrPath] : propertyOrPath;
|
|
761
|
+
const propertyAliases = [property, ...this.getAliases(property)];
|
|
762
|
+
const properties = this.properties({ resolve });
|
|
763
|
+
const match = propertyAliases.find((p) => properties[p]);
|
|
764
|
+
const value = match ? properties[match] : undefined;
|
|
765
|
+
return ((next ? value?.ifObject()?.get([next, ...rest], resolve) : value) ??
|
|
766
|
+
new UndefinedShape({ source: this.getSource() }));
|
|
767
|
+
}
|
|
768
|
+
getDefault(property) {
|
|
769
|
+
return this.defaultProperties[property] ?? new UndefinedShape({ source: this.getSource() });
|
|
770
|
+
}
|
|
771
|
+
keys(nonDefaultsOnly = false) {
|
|
772
|
+
return Object.keys(this.properties({ nonDefaultsOnly }));
|
|
773
|
+
}
|
|
774
|
+
values(options = {}) {
|
|
775
|
+
return Object.values(this.properties(options));
|
|
776
|
+
}
|
|
777
|
+
entries(options = {}) {
|
|
778
|
+
return Object.entries(this.properties(options));
|
|
779
|
+
}
|
|
780
|
+
has(property) {
|
|
781
|
+
return property in this.setProperties;
|
|
782
|
+
}
|
|
783
|
+
omit(properties, options = {}) {
|
|
784
|
+
properties = typeof properties === 'string' ? [properties] : properties;
|
|
785
|
+
const regex = new RegExp(`^(${properties.map((p) => p.replaceAll('$', '\\$')).join('|')})$`);
|
|
786
|
+
return Object.fromEntries(this.entries(options)
|
|
787
|
+
.filter(([k]) => !regex.test(k))
|
|
788
|
+
.map(([k, v]) => [k, v]));
|
|
789
|
+
}
|
|
790
|
+
pick(properties, options = {}) {
|
|
791
|
+
properties = typeof properties === 'string' ? [properties] : properties;
|
|
792
|
+
const regex = new RegExp(`^(${properties.join('|')})$`);
|
|
793
|
+
return Object.fromEntries(this.entries(options)
|
|
794
|
+
.filter(([k]) => regex.test(k))
|
|
795
|
+
.map(([k, v]) => [k, v]));
|
|
796
|
+
}
|
|
797
|
+
setDefaults(defaults) {
|
|
798
|
+
this.defaultProperties = Object.fromEntries(Object.entries(defaults).map(([k, v]) => [k, Shape.from(this.getSource(), v)]));
|
|
799
|
+
for (const [k, v] of Object.entries(this.setProperties)) {
|
|
800
|
+
if (v.isObject() && this.defaultProperties[k]?.isObject()) {
|
|
801
|
+
v.setDefaults(this.defaultProperties[k].getValue());
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return this;
|
|
805
|
+
}
|
|
806
|
+
transform(schema, resolve = true) {
|
|
807
|
+
const properties = {};
|
|
808
|
+
const defaults = {};
|
|
809
|
+
const definedSchema = schema({ merge: MERGE, $: new Transform(this, resolve) });
|
|
810
|
+
for (const to of [...Object.keys(definedSchema), MERGE]) {
|
|
811
|
+
if (definedSchema[to]) {
|
|
812
|
+
const result = definedSchema[to]._(to);
|
|
813
|
+
if (to === MERGE) {
|
|
814
|
+
const { val, def } = result;
|
|
815
|
+
if (val && (typeof val !== 'object' || Array.isArray(val))) {
|
|
816
|
+
throw new Error('Cannot merge non-object value');
|
|
817
|
+
}
|
|
818
|
+
if (def && (typeof def !== 'object' || Array.isArray(def))) {
|
|
819
|
+
throw new Error('Cannot merge non-object default value');
|
|
820
|
+
}
|
|
821
|
+
if (val instanceof ObjectShape) {
|
|
822
|
+
assignWithoutOverwriting(properties, val.setProperties);
|
|
823
|
+
assignWithoutOverwriting(defaults, val.defaultProperties);
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
assignWithoutOverwriting(properties, val);
|
|
827
|
+
}
|
|
828
|
+
if (def instanceof ObjectShape) {
|
|
829
|
+
assignWithoutOverwriting(defaults, def.setProperties);
|
|
830
|
+
}
|
|
831
|
+
else if (def) {
|
|
832
|
+
assignWithoutOverwriting(defaults, def);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
properties[to] = result.val;
|
|
837
|
+
if (result.def !== undefined) {
|
|
838
|
+
defaults[to] = result.def;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return new ObjectShape({
|
|
844
|
+
source: this.getSource(),
|
|
845
|
+
properties,
|
|
846
|
+
}).setDefaults(defaults);
|
|
847
|
+
}
|
|
848
|
+
merge(other) {
|
|
849
|
+
const mergedProperties = { ...this.setProperties };
|
|
850
|
+
const mergedDefaults = { ...this.defaultProperties };
|
|
851
|
+
for (const [a, b] of [
|
|
852
|
+
[mergedProperties, other instanceof ObjectShape ? other.setProperties : other],
|
|
853
|
+
[mergedDefaults, other instanceof ObjectShape ? other.defaultProperties : {}],
|
|
854
|
+
]) {
|
|
855
|
+
for (const [key, v] of Object.entries(b)) {
|
|
856
|
+
const value = Shape.from(this, v);
|
|
857
|
+
if (!(key in a) && value.isUndefined()) {
|
|
858
|
+
// Don't add properties that are undefined
|
|
859
|
+
}
|
|
860
|
+
else if (a[key]?.equals(value)) {
|
|
861
|
+
// Don't overwrite properties that are equal
|
|
862
|
+
}
|
|
863
|
+
else if (a[key]?.isObject() && value.isObject()) {
|
|
864
|
+
a[key].merge(value); // Merge objects recursively
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
a[key] = value;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
return new ObjectShape({
|
|
872
|
+
source: this.getSource(),
|
|
873
|
+
properties: mergedProperties,
|
|
874
|
+
})
|
|
875
|
+
.setDefaults(mergedDefaults)
|
|
876
|
+
.setCreator(this.getCreator());
|
|
877
|
+
}
|
|
878
|
+
equals(other) {
|
|
879
|
+
const otherShape = Shape.from(this, other);
|
|
880
|
+
if (!otherShape.isObject() || this.keys().length !== otherShape.keys().length) {
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
for (const [k, v] of this.entries()) {
|
|
884
|
+
if (!v.equals(otherShape.get(k))) {
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return true;
|
|
889
|
+
}
|
|
890
|
+
getCode() {
|
|
891
|
+
return `{\n ${this.entries({ nonDefaultsOnly: true, resolve: false })
|
|
892
|
+
.map(([k, v]) => `${ObjectShape.quotePropertyNameIfNeeded(k)}: ${v.getCode()}`)
|
|
893
|
+
.join(',\n ')}\n}`;
|
|
894
|
+
}
|
|
895
|
+
static quotePropertyNameIfNeeded(name) {
|
|
896
|
+
return /[^\w$]/.test(name) ? `'${name}'` : name;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
exports.ObjectShape = ObjectShape;
|
|
900
|
+
class CallExpressionShape extends Shape {
|
|
901
|
+
callee;
|
|
902
|
+
args;
|
|
903
|
+
constructor({ source, callee, args }) {
|
|
904
|
+
super({ source });
|
|
905
|
+
this.callee = callee;
|
|
906
|
+
this.args = new ArrayShape({ source, elements: args });
|
|
907
|
+
}
|
|
908
|
+
getCallee() {
|
|
909
|
+
return this.callee;
|
|
910
|
+
}
|
|
911
|
+
getArguments(resolve = true) {
|
|
912
|
+
return this.args.getElements(resolve);
|
|
913
|
+
}
|
|
914
|
+
getArgument(index, resolve = true) {
|
|
915
|
+
return this.args.getElement(index, resolve);
|
|
916
|
+
}
|
|
917
|
+
hasArgument(index) {
|
|
918
|
+
return this.args.hasElement(index);
|
|
919
|
+
}
|
|
920
|
+
getDescription() {
|
|
921
|
+
return `${this.getKind()} (${this.callee})`;
|
|
922
|
+
}
|
|
923
|
+
getCode() {
|
|
924
|
+
return `${this.callee}(${this.args.map((a) => a.getCode(), false).join(', ')})`;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
exports.CallExpressionShape = CallExpressionShape;
|
|
928
|
+
class SourceFileShape extends StringShape {
|
|
929
|
+
path;
|
|
930
|
+
content;
|
|
931
|
+
constructor({ file }) {
|
|
932
|
+
super({ source: file });
|
|
933
|
+
this.path = file.getFilePath();
|
|
934
|
+
this.content = file.getFullText();
|
|
935
|
+
}
|
|
936
|
+
getPath() {
|
|
937
|
+
return this.path;
|
|
938
|
+
}
|
|
939
|
+
getBaseName() {
|
|
940
|
+
return path_1.path.basename(this.path);
|
|
941
|
+
}
|
|
942
|
+
getExtension() {
|
|
943
|
+
return path_1.path.extname(this.path);
|
|
944
|
+
}
|
|
945
|
+
getContent() {
|
|
946
|
+
return this.content;
|
|
947
|
+
}
|
|
948
|
+
getSource() {
|
|
949
|
+
return this.getOriginalNode().asKindOrThrow(typescript_1.ts.SyntaxKind.SourceFile);
|
|
950
|
+
}
|
|
951
|
+
getValue() {
|
|
952
|
+
return this.getContent();
|
|
953
|
+
}
|
|
954
|
+
getCode() {
|
|
955
|
+
return this.getContent();
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
exports.SourceFileShape = SourceFileShape;
|
|
959
|
+
class ElementAccessExpressionShape extends Shape {
|
|
960
|
+
callee;
|
|
961
|
+
arg;
|
|
962
|
+
constructor({ source, callee, arg }) {
|
|
963
|
+
super({ source });
|
|
964
|
+
this.callee = callee;
|
|
965
|
+
this.arg = Shape.from(source, arg)
|
|
966
|
+
.pipe((e) => (e.isResolvable() ? e.resolve() : e))
|
|
967
|
+
.as([
|
|
968
|
+
// I have absolutely no idea why these casts are needed in this file and
|
|
969
|
+
// nowhere else. Seems like a probable TypeScript bug.
|
|
970
|
+
StringShape,
|
|
971
|
+
NumberShape,
|
|
972
|
+
], `Invalid argument to element access expression: ${arg instanceof Shape ? arg.getDescription() : JSON.stringify(arg)}`);
|
|
973
|
+
}
|
|
974
|
+
getCallee() {
|
|
975
|
+
return this.callee;
|
|
976
|
+
}
|
|
977
|
+
getArg() {
|
|
978
|
+
return this.arg;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
exports.ElementAccessExpressionShape = ElementAccessExpressionShape;
|
|
982
|
+
class VariableStatementShape extends Shape {
|
|
983
|
+
variableName;
|
|
984
|
+
initializer;
|
|
985
|
+
_isExported;
|
|
986
|
+
constructor({ source, variableName, initializer, isExported = false, }) {
|
|
987
|
+
super({ source });
|
|
988
|
+
this.variableName =
|
|
989
|
+
variableName instanceof Shape ? variableName : new IdentifierShape({ source, name: variableName });
|
|
990
|
+
this.initializer = Shape.from(source, initializer);
|
|
991
|
+
this._isExported = isExported;
|
|
992
|
+
}
|
|
993
|
+
getVariableName() {
|
|
994
|
+
return this.variableName;
|
|
995
|
+
}
|
|
996
|
+
getInitializer() {
|
|
997
|
+
return this.initializer;
|
|
998
|
+
}
|
|
999
|
+
isExported() {
|
|
1000
|
+
return this._isExported;
|
|
1001
|
+
}
|
|
1002
|
+
getCode() {
|
|
1003
|
+
return `${this.isExported() ? 'export ' : ''}const ${this.getVariableName().getName()} = ${this.getInitializer().getCode()}`;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
exports.VariableStatementShape = VariableStatementShape;
|
|
1007
|
+
function getDefaultCategoryFromTable(table) {
|
|
1008
|
+
return table === 'sys_app' ? 'scope' : 'update';
|
|
1009
|
+
}
|
|
1010
|
+
function getInstallCategoryFromInstallMethod(installMethod) {
|
|
1011
|
+
return installMethod === 'demo' ? 'unload.demo' : 'unload';
|
|
1012
|
+
}
|
|
1013
|
+
function getInstallCategory(source, table) {
|
|
1014
|
+
let installCategory = getDefaultCategoryFromTable(table);
|
|
1015
|
+
if (source instanceof CallExpressionShape) {
|
|
1016
|
+
const installMethod = source.getArgument(0).ifObject()?.get(['$meta', 'installMethod']).ifString()?.getValue();
|
|
1017
|
+
if (installMethod) {
|
|
1018
|
+
installCategory = getInstallCategoryFromInstallMethod(installMethod);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
return installCategory;
|
|
1022
|
+
}
|
|
1023
|
+
class Record extends ObjectShape {
|
|
1024
|
+
id;
|
|
1025
|
+
related = [];
|
|
1026
|
+
action;
|
|
1027
|
+
installCategory;
|
|
1028
|
+
constructor({ source, id, properties, action = 'INSERT_OR_UPDATE', installCategory = getDefaultCategoryFromTable(id.getTable()), }) {
|
|
1029
|
+
super({ source, properties });
|
|
1030
|
+
this.action = action;
|
|
1031
|
+
this.id = id;
|
|
1032
|
+
this.installCategory = installCategory;
|
|
1033
|
+
}
|
|
1034
|
+
static isDeleteAction(action) {
|
|
1035
|
+
return action === 'DELETE' || action === 'delete_multiple';
|
|
1036
|
+
}
|
|
1037
|
+
getId() {
|
|
1038
|
+
return this.id;
|
|
1039
|
+
}
|
|
1040
|
+
getInstallCategory() {
|
|
1041
|
+
return this.installCategory;
|
|
1042
|
+
}
|
|
1043
|
+
getTable() {
|
|
1044
|
+
return this.id.getTable();
|
|
1045
|
+
}
|
|
1046
|
+
getAction() {
|
|
1047
|
+
return this.action;
|
|
1048
|
+
}
|
|
1049
|
+
isDeleted() {
|
|
1050
|
+
return Record.isDeleteAction(this.getAction());
|
|
1051
|
+
}
|
|
1052
|
+
getUpdateName() {
|
|
1053
|
+
return this.id.getUpdateName();
|
|
1054
|
+
}
|
|
1055
|
+
with(...related) {
|
|
1056
|
+
this.related.length = 0;
|
|
1057
|
+
this.related.push(...related);
|
|
1058
|
+
return this;
|
|
1059
|
+
}
|
|
1060
|
+
flat() {
|
|
1061
|
+
return [this, ...this.related.flatMap((r) => r.flat())];
|
|
1062
|
+
}
|
|
1063
|
+
getCount() {
|
|
1064
|
+
return 1 + this.related.reduce((count, r) => count + r.getCount(), 0);
|
|
1065
|
+
}
|
|
1066
|
+
merge(other) {
|
|
1067
|
+
return new Record({
|
|
1068
|
+
source: this.getSource(),
|
|
1069
|
+
id: this.getId(),
|
|
1070
|
+
action: other instanceof Record ? other.getAction() : this.getAction(),
|
|
1071
|
+
installCategory: this.getInstallCategory(),
|
|
1072
|
+
properties: super.merge(other),
|
|
1073
|
+
}).setCreator(this.getCreator());
|
|
1074
|
+
}
|
|
1075
|
+
equals(other) {
|
|
1076
|
+
return this.getId().equals(other);
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Useful when you need to know if this record is equal to another not
|
|
1080
|
+
* just in terms of its identity but also its data.
|
|
1081
|
+
*/
|
|
1082
|
+
strictEquals(other) {
|
|
1083
|
+
if (!this.equals(other)) {
|
|
1084
|
+
return false;
|
|
1085
|
+
}
|
|
1086
|
+
if (!(other instanceof Record)) {
|
|
1087
|
+
return false;
|
|
1088
|
+
}
|
|
1089
|
+
return this.getAction() === other.getAction() && super.equals(other);
|
|
1090
|
+
}
|
|
1091
|
+
setCreator(creator, overwrite = false) {
|
|
1092
|
+
this.related.forEach((r) => r.setCreator(creator, overwrite));
|
|
1093
|
+
return super.setCreator(creator, overwrite);
|
|
1094
|
+
}
|
|
1095
|
+
toRecordId() {
|
|
1096
|
+
return this.id;
|
|
1097
|
+
}
|
|
1098
|
+
toString() {
|
|
1099
|
+
return this.id;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
exports.Record = Record;
|
|
1103
|
+
class RecordId extends StringShape {
|
|
1104
|
+
table;
|
|
1105
|
+
guid;
|
|
1106
|
+
keys;
|
|
1107
|
+
nowIdKey;
|
|
1108
|
+
constructor({ source, table, guid, keys: rawKeys, nowIdKey, }) {
|
|
1109
|
+
const keys = rawKeys instanceof ObjectShape
|
|
1110
|
+
? Object.fromEntries(rawKeys.entries().map(([k, v]) => [k, v.ifString()?.getValue() ?? v.toRecordId()]))
|
|
1111
|
+
: rawKeys;
|
|
1112
|
+
if (keys && Object.keys(keys).length <= 0) {
|
|
1113
|
+
throw new Error('Failed to create RecordId shape. Coalesce keys must contain at least one entry.');
|
|
1114
|
+
}
|
|
1115
|
+
super({ source });
|
|
1116
|
+
this.table = table;
|
|
1117
|
+
this.guid = guid;
|
|
1118
|
+
this.keys = keys;
|
|
1119
|
+
this.nowIdKey = nowIdKey;
|
|
1120
|
+
}
|
|
1121
|
+
getTable() {
|
|
1122
|
+
return this.table;
|
|
1123
|
+
}
|
|
1124
|
+
getGuidProducer() {
|
|
1125
|
+
return this.guid;
|
|
1126
|
+
}
|
|
1127
|
+
getNowIdKey() {
|
|
1128
|
+
return this.nowIdKey;
|
|
1129
|
+
}
|
|
1130
|
+
getKeys() {
|
|
1131
|
+
return this.keys;
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Similar to `getKeys`, but resolves any nested record IDs to their GUID values
|
|
1135
|
+
*/
|
|
1136
|
+
resolveKeys() {
|
|
1137
|
+
if (!this.keys) {
|
|
1138
|
+
return undefined;
|
|
1139
|
+
}
|
|
1140
|
+
return Object.fromEntries(Object.entries(this.keys).map(([k, v]) => [k, typeof v === 'string' ? v : v.getValue()]));
|
|
1141
|
+
}
|
|
1142
|
+
getKey(key) {
|
|
1143
|
+
return this.getKeys()?.[key];
|
|
1144
|
+
}
|
|
1145
|
+
getPrimaryKey() {
|
|
1146
|
+
const keyValues = Object.values(this.keys ?? {});
|
|
1147
|
+
const [primaryKeyValue] = keyValues;
|
|
1148
|
+
if (keyValues.length !== 1 || !primaryKeyValue || typeof primaryKeyValue !== 'string') {
|
|
1149
|
+
throw new Error("Tried to get primary key of record ID that doesn't have one");
|
|
1150
|
+
}
|
|
1151
|
+
return primaryKeyValue;
|
|
1152
|
+
}
|
|
1153
|
+
hasPrimaryKey() {
|
|
1154
|
+
return !!this.keys && Object.keys(this.keys).length === 1;
|
|
1155
|
+
}
|
|
1156
|
+
getUpdateName() {
|
|
1157
|
+
// TODO: Provide a way to override this for non-standard coalesce strategies, or
|
|
1158
|
+
// just hard-code the very short list of special cases from UpdateName.java
|
|
1159
|
+
return `${this.table}_${this.getValue()}`;
|
|
1160
|
+
}
|
|
1161
|
+
getValue() {
|
|
1162
|
+
return typeof this.guid === 'string' ? this.guid : this.guid();
|
|
1163
|
+
}
|
|
1164
|
+
equals(other) {
|
|
1165
|
+
const otherShape = Shape.from(this, other);
|
|
1166
|
+
if (otherShape.isRecord()) {
|
|
1167
|
+
return this.equals(otherShape.getId());
|
|
1168
|
+
}
|
|
1169
|
+
if (otherShape.isRecordId()) {
|
|
1170
|
+
return (this.getTable() === otherShape.getTable() &&
|
|
1171
|
+
(this.getValue() === otherShape.getValue() ||
|
|
1172
|
+
(this.keys !== undefined && _.isEqual(this.keys, otherShape.keys))));
|
|
1173
|
+
}
|
|
1174
|
+
return (this.hasPrimaryKey() && otherShape.equals(this.getPrimaryKey())) || super.equals(other);
|
|
1175
|
+
}
|
|
1176
|
+
getCode() {
|
|
1177
|
+
return `'${this.hasPrimaryKey() ? this.getPrimaryKey() : this.getValue()}'`;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
exports.RecordId = RecordId;
|
|
1181
|
+
//# sourceMappingURL=shape.js.map
|