@ja-platform/parser-schema 0.0.0-dev-20261019214152
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/@types/Version.d.ts +19 -0
- package/dist/@types/day/Day.d.ts +4 -0
- package/dist/@types/day/DayConstructorInterface.d.ts +50 -0
- package/dist/@types/day/DayInterface.d.ts +34 -0
- package/dist/@types/day/index.d.ts +2 -0
- package/dist/@types/day/utils.d.ts +4 -0
- package/dist/@types/expressions/SchemaObjectDisplayExpression.d.ts +17 -0
- package/dist/@types/index.d.ts +16 -0
- package/dist/@types/schema/ModelIndex.d.ts +19 -0
- package/dist/@types/schema/Schema.d.ts +51 -0
- package/dist/@types/schema/SchemaParserErrors.d.ts +10 -0
- package/dist/@types/schema/TypeFactory.d.ts +26 -0
- package/dist/@types/schema/reservedNames.d.ts +7 -0
- package/dist/@types/schema/schemaParser.d.ts +43 -0
- package/dist/@types/schema/schemaSerializer.d.ts +11 -0
- package/dist/@types/types/EnumOption.d.ts +15 -0
- package/dist/@types/types/FunctionType.d.ts +15 -0
- package/dist/@types/types/Param.d.ts +19 -0
- package/dist/@types/types/QueryType.d.ts +19 -0
- package/dist/@types/types/Relationship.d.ts +20 -0
- package/dist/@types/types/SchemaModelType.d.ts +89 -0
- package/dist/@types/types/Variable.d.ts +32 -0
- package/dist/@types/types/primitives/Boolean.d.ts +21 -0
- package/dist/@types/types/primitives/ChoiceType.d.ts +47 -0
- package/dist/@types/types/primitives/Date.d.ts +13 -0
- package/dist/@types/types/primitives/Datetime.d.ts +9 -0
- package/dist/@types/types/primitives/GeoTrack.d.ts +5 -0
- package/dist/@types/types/primitives/Location.d.ts +6 -0
- package/dist/@types/types/primitives/MultipleChoice.d.ts +5 -0
- package/dist/@types/types/primitives/MultipleChoiceInteger.d.ts +8 -0
- package/dist/@types/types/primitives/SingleChoice.d.ts +5 -0
- package/dist/@types/types/primitives/SingleChoiceInteger.d.ts +8 -0
- package/dist/@types/types/primitives/Text.d.ts +8 -0
- package/dist/@types/types/primitives/attachments/Attachment.d.ts +9 -0
- package/dist/@types/types/primitives/attachments/Photo.d.ts +6 -0
- package/dist/@types/types/primitives/attachments/Signature.d.ts +6 -0
- package/dist/@types/types/primitives/index.d.ts +67 -0
- package/dist/Version.js +76 -0
- package/dist/Version.js.map +1 -0
- package/dist/day/Day.js +112 -0
- package/dist/day/Day.js.map +1 -0
- package/dist/day/DayConstructorInterface.js +3 -0
- package/dist/day/DayConstructorInterface.js.map +1 -0
- package/dist/day/DayInterface.js +3 -0
- package/dist/day/DayInterface.js.map +1 -0
- package/dist/day/index.js +19 -0
- package/dist/day/index.js.map +1 -0
- package/dist/day/utils.js +43 -0
- package/dist/day/utils.js.map +1 -0
- package/dist/expressions/SchemaObjectDisplayExpression.js +40 -0
- package/dist/expressions/SchemaObjectDisplayExpression.js.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/schema/ModelIndex.js +14 -0
- package/dist/schema/ModelIndex.js.map +1 -0
- package/dist/schema/Schema.js +132 -0
- package/dist/schema/Schema.js.map +1 -0
- package/dist/schema/SchemaParserErrors.js +26 -0
- package/dist/schema/SchemaParserErrors.js.map +1 -0
- package/dist/schema/TypeFactory.js +21 -0
- package/dist/schema/TypeFactory.js.map +1 -0
- package/dist/schema/reservedNames.js +101 -0
- package/dist/schema/reservedNames.js.map +1 -0
- package/dist/schema/schemaParser.js +1135 -0
- package/dist/schema/schemaParser.js.map +1 -0
- package/dist/schema/schemaSerializer.js +181 -0
- package/dist/schema/schemaSerializer.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/EnumOption.js +22 -0
- package/dist/types/EnumOption.js.map +1 -0
- package/dist/types/FunctionType.js +30 -0
- package/dist/types/FunctionType.js.map +1 -0
- package/dist/types/Param.js +35 -0
- package/dist/types/Param.js.map +1 -0
- package/dist/types/QueryType.js +37 -0
- package/dist/types/QueryType.js.map +1 -0
- package/dist/types/Relationship.js +25 -0
- package/dist/types/Relationship.js.map +1 -0
- package/dist/types/SchemaModelType.js +147 -0
- package/dist/types/SchemaModelType.js.map +1 -0
- package/dist/types/Variable.js +49 -0
- package/dist/types/Variable.js.map +1 -0
- package/dist/types/primitives/Boolean.js +9 -0
- package/dist/types/primitives/Boolean.js.map +1 -0
- package/dist/types/primitives/ChoiceType.js +65 -0
- package/dist/types/primitives/ChoiceType.js.map +1 -0
- package/dist/types/primitives/Date.js +68 -0
- package/dist/types/primitives/Date.js.map +1 -0
- package/dist/types/primitives/Datetime.js +31 -0
- package/dist/types/primitives/Datetime.js.map +1 -0
- package/dist/types/primitives/GeoTrack.js +12 -0
- package/dist/types/primitives/GeoTrack.js.map +1 -0
- package/dist/types/primitives/Location.js +18 -0
- package/dist/types/primitives/Location.js.map +1 -0
- package/dist/types/primitives/MultipleChoice.js +12 -0
- package/dist/types/primitives/MultipleChoice.js.map +1 -0
- package/dist/types/primitives/MultipleChoiceInteger.js +34 -0
- package/dist/types/primitives/MultipleChoiceInteger.js.map +1 -0
- package/dist/types/primitives/SingleChoice.js +12 -0
- package/dist/types/primitives/SingleChoice.js.map +1 -0
- package/dist/types/primitives/SingleChoiceInteger.js +38 -0
- package/dist/types/primitives/SingleChoiceInteger.js.map +1 -0
- package/dist/types/primitives/Text.js +22 -0
- package/dist/types/primitives/Text.js.map +1 -0
- package/dist/types/primitives/attachments/Attachment.js +16 -0
- package/dist/types/primitives/attachments/Attachment.js.map +1 -0
- package/dist/types/primitives/attachments/Photo.js +16 -0
- package/dist/types/primitives/attachments/Photo.js.map +1 -0
- package/dist/types/primitives/attachments/Signature.js +16 -0
- package/dist/types/primitives/attachments/Signature.js.map +1 -0
- package/dist/types/primitives/index.js +85 -0
- package/dist/types/primitives/index.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryType = void 0;
|
|
4
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
5
|
+
/**
|
|
6
|
+
* A query whose results share a value type.
|
|
7
|
+
*/
|
|
8
|
+
class QueryType extends parser_type_system_1.Type {
|
|
9
|
+
constructor(itemType) {
|
|
10
|
+
super('query');
|
|
11
|
+
this.itemType = itemType;
|
|
12
|
+
this._typeName = 'query';
|
|
13
|
+
this.name = 'query';
|
|
14
|
+
this.isCollection = true;
|
|
15
|
+
}
|
|
16
|
+
static isInstanceOf(type) {
|
|
17
|
+
return (type === null || type === void 0 ? void 0 : type._typeName) === 'query';
|
|
18
|
+
}
|
|
19
|
+
is(value) {
|
|
20
|
+
return (parser_type_system_1.ObjectType.isInstanceOf(value === null || value === void 0 ? void 0 : value.type) &&
|
|
21
|
+
value.type.name === this.itemType.name &&
|
|
22
|
+
typeof value._fetch === 'function');
|
|
23
|
+
}
|
|
24
|
+
parse(value) {
|
|
25
|
+
if (this.is(value))
|
|
26
|
+
return value;
|
|
27
|
+
throw new Error(`Expected value to have query type ${this.itemType.name}`);
|
|
28
|
+
}
|
|
29
|
+
stringify() {
|
|
30
|
+
return `${this.name}:${this.itemType.name}`;
|
|
31
|
+
}
|
|
32
|
+
toJSON() {
|
|
33
|
+
return { type: this.name, object: this.itemType.name };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.QueryType = QueryType;
|
|
37
|
+
//# sourceMappingURL=QueryType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryType.js","sourceRoot":"","sources":["../../src/types/QueryType.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEnE;;GAEG;AACH,eAAuB,SAAQ,yBAAI;IAKjC,YAAqB,QAAc;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QADI,aAAQ,GAAR,QAAQ,CAAM;QAJ1B,cAAS,GAAG,OAAO,CAAC;QACpB,SAAI,GAAG,OAAO,CAAC;QACf,iBAAY,GAAG,IAAI,CAAC;IAI7B,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAiB;QACnC,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,MAAK,OAAO,CAAC;IACrC,CAAC;IAED,EAAE,CAAC,KAAU;QACX,OAAO,CACL,+BAAU,CAAC,YAAY,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI;YACtC,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,CACnC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAc;QAClB,IAAI,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,qCAAqC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,SAAS;QACP,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC9C,CAAC;IAED,MAAM;QACJ,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzD,CAAC;CACF","sourcesContent":["import { Type, ObjectType } from '@ja-platform/parser-type-system';\n\n/**\n * A query whose results share a value type.\n */\nexport class QueryType extends Type {\n readonly _typeName = 'query';\n readonly name = 'query';\n readonly isCollection = true;\n\n constructor(readonly itemType: Type) {\n super('query');\n }\n\n static isInstanceOf(type: Type | null): type is QueryType {\n return type?._typeName === 'query';\n }\n\n is(value: any): boolean {\n return (\n ObjectType.isInstanceOf(value?.type) &&\n value.type.name === this.itemType.name &&\n typeof value._fetch === 'function'\n );\n }\n\n parse(value: unknown): unknown {\n if (this.is(value)) return value;\n throw new Error(`Expected value to have query type ${this.itemType.name}`);\n }\n\n stringify(): string {\n return `${this.name}:${this.itemType.name}`;\n }\n\n toJSON() {\n return { type: this.name, object: this.itemType.name };\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationshipTypeFactory = exports.Relationship = void 0;
|
|
4
|
+
const TypeFactory_1 = require("../schema/TypeFactory");
|
|
5
|
+
class Relationship {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.type = 'one-to-many';
|
|
8
|
+
this.objectType = null;
|
|
9
|
+
this.foreignType = null;
|
|
10
|
+
this.name = null;
|
|
11
|
+
this.foreignName = null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Relationship = Relationship;
|
|
15
|
+
Relationship.TYPE = 'relationship';
|
|
16
|
+
class RelationshipTypeFactory extends TypeFactory_1.AbstractObjectTypeFactory {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(Relationship.TYPE);
|
|
19
|
+
}
|
|
20
|
+
generate() {
|
|
21
|
+
return new Relationship();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.RelationshipTypeFactory = RelationshipTypeFactory;
|
|
25
|
+
//# sourceMappingURL=Relationship.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Relationship.js","sourceRoot":"","sources":["../../src/types/Relationship.ts"],"names":[],"mappings":";;;AAAA,uDAAkE;AAGlE;IAkBE;QACE,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAE1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF;;AA1BiB,iBAAI,GAAG,cAAc,CAAC;AA4BxC,6BAAqC,SAAQ,uCAAuC;IAClF;QACE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,YAAY,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { AbstractObjectTypeFactory } from '../schema/TypeFactory';\nimport { SchemaModelType } from './SchemaModelType';\n\nexport class Relationship {\n static readonly TYPE = 'relationship';\n\n /** one-to-many, many-to-many, one-to-one */\n type: string;\n\n /** local object type (containing the belongs_to) */\n objectType: SchemaModelType; // TODO\n\n /** foreign object type (containing the has_many) */\n foreignType: SchemaModelType; // TODO\n\n /** The name used on the local object to identify the relationship (singular) */\n name: string;\n\n /** The name used on the foreign object to identify the relationship (plural) */\n foreignName: string;\n\n constructor() {\n this.type = 'one-to-many';\n\n this.objectType = null;\n this.foreignType = null;\n\n this.name = null;\n this.foreignName = null;\n }\n}\n\nexport class RelationshipTypeFactory extends AbstractObjectTypeFactory<Relationship> {\n constructor() {\n super(Relationship.TYPE);\n }\n\n generate(): Relationship {\n return new Relationship();\n }\n}\n"]}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaModelTypeFactory = exports.SchemaModelType = void 0;
|
|
4
|
+
const QueryType_1 = require("./QueryType");
|
|
5
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
6
|
+
const primitives_1 = require("./primitives");
|
|
7
|
+
const TypeFactory_1 = require("../schema/TypeFactory");
|
|
8
|
+
class SchemaModelType extends parser_type_system_1.ObjectType {
|
|
9
|
+
static isInstanceOf(type) {
|
|
10
|
+
return (type === null || type === void 0 ? void 0 : type._typeName) === SchemaModelType.TYPE;
|
|
11
|
+
}
|
|
12
|
+
constructor(name) {
|
|
13
|
+
super(name);
|
|
14
|
+
this.isPrimitiveType = false;
|
|
15
|
+
this.isObject = true;
|
|
16
|
+
this.attributes = {};
|
|
17
|
+
this.displayFormat = null;
|
|
18
|
+
this.belongsTo = {};
|
|
19
|
+
this.hasMany = {};
|
|
20
|
+
this.belongsToVars = {};
|
|
21
|
+
this.belongsToIdVars = {};
|
|
22
|
+
this.hasManyVars = {};
|
|
23
|
+
this.indexes = [];
|
|
24
|
+
this.allIndexes = [];
|
|
25
|
+
this.errors = [];
|
|
26
|
+
this.webhooks = [];
|
|
27
|
+
this.notifyUsers = [];
|
|
28
|
+
}
|
|
29
|
+
addAttribute(attribute) {
|
|
30
|
+
this.attributes[attribute.name] = attribute;
|
|
31
|
+
}
|
|
32
|
+
setupVariables(schema) {
|
|
33
|
+
this.idVar = schema.variable('id', primitives_1.PrimitiveType.TEXT);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Attribute or relationship variable.
|
|
37
|
+
*/
|
|
38
|
+
getAttribute(name) {
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(this.attributes, name)) {
|
|
40
|
+
return this.attributes[name];
|
|
41
|
+
}
|
|
42
|
+
else if (Object.prototype.hasOwnProperty.call(this.belongsToVars, name)) {
|
|
43
|
+
return this.belongsToVars[name];
|
|
44
|
+
}
|
|
45
|
+
else if (Object.prototype.hasOwnProperty.call(this.belongsToIdVars, name)) {
|
|
46
|
+
return this.belongsToIdVars[name];
|
|
47
|
+
}
|
|
48
|
+
else if (Object.prototype.hasOwnProperty.call(this.hasManyVars, name)) {
|
|
49
|
+
return this.hasManyVars[name];
|
|
50
|
+
}
|
|
51
|
+
else if (name == 'id') {
|
|
52
|
+
return this.idVar;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getField(name) {
|
|
59
|
+
var _a;
|
|
60
|
+
var _b;
|
|
61
|
+
return (_b = (_a = this.getAttribute(name)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : null;
|
|
62
|
+
}
|
|
63
|
+
getAttributes() {
|
|
64
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.hasManyVars), this.belongsToIdVars), this.belongsToVars), this.attributes), { id: this.idVar });
|
|
65
|
+
}
|
|
66
|
+
toJSON() {
|
|
67
|
+
var _a;
|
|
68
|
+
var _b;
|
|
69
|
+
let belongsTo = {};
|
|
70
|
+
// hasMany is not populated yet
|
|
71
|
+
const hasMany = {};
|
|
72
|
+
for (let key in this.belongsTo) {
|
|
73
|
+
if (this.belongsTo.hasOwnProperty(key)) {
|
|
74
|
+
const rel = this.belongsTo[key];
|
|
75
|
+
belongsTo[rel.name] = {
|
|
76
|
+
type: rel.foreignType.name,
|
|
77
|
+
foreignName: rel.foreignName
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
label: this.label,
|
|
83
|
+
attributes: this.attributes,
|
|
84
|
+
belongsTo: belongsTo,
|
|
85
|
+
hasMany: hasMany,
|
|
86
|
+
display: (_b = (_a = this.displayFormat) === null || _a === void 0 ? void 0 : _a.raw()) !== null && _b !== void 0 ? _b : ''
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
addBelongsTo(options) {
|
|
90
|
+
const object = this;
|
|
91
|
+
const schema = options.schema;
|
|
92
|
+
let err;
|
|
93
|
+
const rel = schema.newRelationship();
|
|
94
|
+
const typeName = options.type;
|
|
95
|
+
const foreignName = options.foreignName;
|
|
96
|
+
if (typeName != null) {
|
|
97
|
+
let name = options.name;
|
|
98
|
+
if (name == null || name === '') {
|
|
99
|
+
name = typeName;
|
|
100
|
+
}
|
|
101
|
+
rel.name = name;
|
|
102
|
+
rel.objectType = object;
|
|
103
|
+
rel.foreignType = schema.objects[typeName];
|
|
104
|
+
if (rel.foreignType == null) {
|
|
105
|
+
err = new Error("Object '" + typeName + "' is not defined");
|
|
106
|
+
err.attribute = 'type';
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
if (object.belongsTo.hasOwnProperty(name)) {
|
|
110
|
+
err = new Error("Relationship '" + name + "' is already defined");
|
|
111
|
+
err.attribute = 'name';
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
object.belongsTo[name] = rel;
|
|
116
|
+
// For type lookups
|
|
117
|
+
object.belongsToVars[name] = schema.variable(name, rel.foreignType);
|
|
118
|
+
object.belongsToVars[name].relationship = name;
|
|
119
|
+
const idVar = schema.variable(name + '_id', primitives_1.PrimitiveType.TEXT);
|
|
120
|
+
idVar.relationship = name;
|
|
121
|
+
idVar.isBelongsToId = true;
|
|
122
|
+
object.belongsToIdVars[idVar.name] = idVar;
|
|
123
|
+
}
|
|
124
|
+
if (foreignName != null) {
|
|
125
|
+
rel.foreignName = foreignName;
|
|
126
|
+
rel.foreignType.hasMany[foreignName] = rel;
|
|
127
|
+
rel.foreignType.hasManyVars[foreignName] = schema.variable(foreignName, new QueryType_1.QueryType(object));
|
|
128
|
+
}
|
|
129
|
+
return rel;
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.SchemaModelType = SchemaModelType;
|
|
135
|
+
SchemaModelType.TYPE = 'object';
|
|
136
|
+
class SchemaModelTypeFactory extends TypeFactory_1.AbstractObjectTypeFactory {
|
|
137
|
+
constructor() {
|
|
138
|
+
super(SchemaModelType.TYPE);
|
|
139
|
+
}
|
|
140
|
+
generate(event) {
|
|
141
|
+
const instance = new SchemaModelType(event.name);
|
|
142
|
+
instance.setupVariables(event.schema);
|
|
143
|
+
return instance;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.SchemaModelTypeFactory = SchemaModelTypeFactory;
|
|
147
|
+
//# sourceMappingURL=SchemaModelType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaModelType.js","sourceRoot":"","sources":["../../src/types/SchemaModelType.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AACxC,wEAAmE;AAMnE,6CAAuD;AACvD,uDAAqF;AASrF,qBAA6B,SAAQ,+BAAU;IAO7C,MAAM,CAAC,Y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CACF;;AAvKiB,oBAAI,GAAG,QAAQ,AAAX,CAAY;AA6KlC,4BAAoC,SAAQ,uCAAwE;IAClH;QACE,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,QAAQ,CAAC,KAAmC;QAC1C,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjD,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { SchemaObjectDisplayExpression } from '../expressions/SchemaObjectDisplayExpression';\nimport { QueryType } from './QueryType';\nimport { ObjectType, Type } from '@ja-platform/parser-type-system';\nimport { Variable } from './Variable';\nimport { Relationship } from './Relationship';\nimport { Schema } from '../schema/Schema';\nimport { XMLElement } from '@journeyapps/domparser/types';\nimport { ModelIndex } from '../schema/ModelIndex';\nimport { PrimitiveType, TextType } from './primitives';\nimport { AbstractObjectTypeFactory, GenerateTypeEvent } from '../schema/TypeFactory';\n\nexport interface NotificationConfig {\n message: SchemaObjectDisplayExpression;\n recipient: string;\n received: string;\n badgeCount: string;\n}\n\nexport class SchemaModelType extends ObjectType {\n static readonly TYPE = 'object';\n\n readonly isPrimitiveType = false;\n readonly isObject = true;\n attributes: Record<string, Variable> = {};\n\n static isInstanceOf(type: any): type is SchemaModelType {\n return type?._typeName === SchemaModelType.TYPE;\n }\n\n displayFormat: SchemaObjectDisplayExpression | null;\n displaySource?: XMLElement;\n label: string;\n\n belongsTo: { [index: string]: Relationship };\n hasMany: { [index: string]: Relationship };\n\n belongsToVars: { [index: string]: Variable };\n belongsToIdVars: { [index: string]: Variable };\n hasManyVars: { [index: string]: Variable };\n idVar: Variable<TextType>;\n\n /**\n * App and Cloud indexes.\n */\n allIndexes: ModelIndex[];\n /**\n * App indexes.\n */\n indexes: ModelIndex[];\n errors: any[]; // TODO\n webhooks: any[]; // TODO\n notifyUsers: NotificationConfig[];\n\n sourceElement: XMLElement;\n\n constructor(name?: string) {\n super(name);\n\n this.displayFormat = null;\n this.belongsTo = {};\n this.hasMany = {};\n this.belongsToVars = {};\n this.belongsToIdVars = {};\n this.hasManyVars = {};\n this.indexes = [];\n this.allIndexes = [];\n this.errors = [];\n this.webhooks = [];\n\n this.notifyUsers = [];\n }\n\n addAttribute(attribute: Variable): void {\n this.attributes[attribute.name] = attribute;\n }\n\n setupVariables(schema: Schema) {\n this.idVar = schema.variable('id', PrimitiveType.TEXT);\n }\n\n /**\n * Attribute or relationship variable.\n */\n getAttribute(name: string): Variable | null {\n if (Object.prototype.hasOwnProperty.call(this.attributes, name)) {\n return this.attributes[name];\n } else if (Object.prototype.hasOwnProperty.call(this.belongsToVars, name)) {\n return this.belongsToVars[name];\n } else if (Object.prototype.hasOwnProperty.call(this.belongsToIdVars, name)) {\n return this.belongsToIdVars[name];\n } else if (Object.prototype.hasOwnProperty.call(this.hasManyVars, name)) {\n return this.hasManyVars[name];\n } else if (name == 'id') {\n return this.idVar;\n } else {\n return null;\n }\n }\n\n getField(name: string): Type | null {\n return this.getAttribute(name)?.type ?? null;\n }\n\n getAttributes(): { [index: string]: Variable } {\n return {\n ...this.hasManyVars,\n ...this.belongsToIdVars,\n ...this.belongsToVars,\n ...this.attributes,\n id: this.idVar\n };\n }\n\n toJSON() {\n let belongsTo: {\n [index: string]: { type: string; foreignName: string };\n } = {};\n // hasMany is not populated yet\n const hasMany = {};\n\n for (let key in this.belongsTo) {\n if (this.belongsTo.hasOwnProperty(key)) {\n const rel = this.belongsTo[key];\n belongsTo[rel.name] = {\n type: rel.foreignType.name,\n foreignName: rel.foreignName\n };\n }\n }\n\n return {\n label: this.label,\n attributes: this.attributes,\n belongsTo: belongsTo,\n hasMany: hasMany,\n display: this.displayFormat?.raw() ?? ''\n };\n }\n\n addBelongsTo(options: { schema: Schema; type?: string; foreignName?: string; name: string }) {\n const object = this;\n const schema = options.schema;\n let err;\n const rel = schema.newRelationship();\n const typeName = options.type;\n const foreignName = options.foreignName;\n if (typeName != null) {\n let name = options.name;\n if (name == null || name === '') {\n name = typeName;\n }\n rel.name = name;\n rel.objectType = object;\n rel.foreignType = schema.objects[typeName];\n if (rel.foreignType == null) {\n err = new Error(\"Object '\" + typeName + \"' is not defined\");\n (err as any).attribute = 'type';\n throw err;\n }\n\n if (object.belongsTo.hasOwnProperty(name)) {\n err = new Error(\"Relationship '\" + name + \"' is already defined\");\n (err as any).attribute = 'name';\n throw err;\n } else {\n object.belongsTo[name] = rel;\n\n // For type lookups\n object.belongsToVars[name] = schema.variable(name, rel.foreignType);\n object.belongsToVars[name].relationship = name;\n\n const idVar = schema.variable(name + '_id', PrimitiveType.TEXT);\n idVar.relationship = name;\n idVar.isBelongsToId = true;\n object.belongsToIdVars[idVar.name] = idVar;\n }\n\n if (foreignName != null) {\n rel.foreignName = foreignName;\n rel.foreignType.hasMany[foreignName] = rel;\n rel.foreignType.hasManyVars[foreignName] = schema.variable(foreignName, new QueryType(object));\n }\n return rel;\n }\n return null;\n }\n}\n\nexport interface GenerateSchemaModelTypeEvent extends GenerateTypeEvent {\n name?: string;\n}\n\nexport class SchemaModelTypeFactory extends AbstractObjectTypeFactory<SchemaModelType, GenerateSchemaModelTypeEvent> {\n constructor() {\n super(SchemaModelType.TYPE);\n }\n\n generate(event: GenerateSchemaModelTypeEvent) {\n const instance = new SchemaModelType(event.name);\n instance.setupVariables(event.schema);\n return instance;\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VariableFactory = exports.Variable = void 0;
|
|
4
|
+
const TypeFactory_1 = require("../schema/TypeFactory");
|
|
5
|
+
const SchemaModelType_1 = require("./SchemaModelType");
|
|
6
|
+
// Variable constructor. A variable is simply a name and a type (can be null).
|
|
7
|
+
class Variable {
|
|
8
|
+
static isInstanceOf(obj) {
|
|
9
|
+
return obj instanceof Variable || 'name' in obj;
|
|
10
|
+
}
|
|
11
|
+
constructor(name, type) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.errors = [];
|
|
15
|
+
}
|
|
16
|
+
toJSON() {
|
|
17
|
+
const result = {
|
|
18
|
+
name: this.name,
|
|
19
|
+
type: undefined
|
|
20
|
+
};
|
|
21
|
+
if (this.type != null) {
|
|
22
|
+
result.type = this.type.name;
|
|
23
|
+
}
|
|
24
|
+
if (typeof this.label != 'undefined') {
|
|
25
|
+
result.label = this.label;
|
|
26
|
+
}
|
|
27
|
+
if (this.type != null && !(this.type instanceof SchemaModelType_1.SchemaModelType)) {
|
|
28
|
+
const typeJson = this.type.toJSON();
|
|
29
|
+
Object.assign(result, typeJson);
|
|
30
|
+
}
|
|
31
|
+
if (this.relationship != null) {
|
|
32
|
+
result.relationship = this.relationship;
|
|
33
|
+
result.isRelationshipId = this.isRelationshipId;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.Variable = Variable;
|
|
39
|
+
Variable.TYPE = 'variable';
|
|
40
|
+
class VariableFactory extends TypeFactory_1.AbstractObjectTypeFactory {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(Variable.TYPE);
|
|
43
|
+
}
|
|
44
|
+
generate(event) {
|
|
45
|
+
return new Variable(event.name, event.type);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.VariableFactory = VariableFactory;
|
|
49
|
+
//# sourceMappingURL=Variable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Variable.js","sourceRoot":"","sources":["../../src/types/Variable.ts"],"names":[],"mappings":";;;AAAA,uDAAqF;AAErF,uDAAoD;AAUpD,8EAA8E;AAC9E;IAGE,MAAM,CAAC,YAAY,CAAC,GAAQ;QAC1B,OAAO,GAAG,YAAY,QAAQ,IAAI,MAAM,IAAI,GAAG,CAAC;IAClD,CAAC;IAYD,YAAY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AAC;IACjD,CAAC;CACF","sourcesContent":["import { AbstractObjectTypeFactory, GenerateTypeEvent } from '../schema/TypeFactory';\nimport { Type } from '@ja-platform/parser-type-system';\nimport { SchemaModelType } from './SchemaModelType';\nimport { XMLElement } from '@journeyapps/domparser/types';\n\nexport interface VariableJsonType {\n name: string;\n type: string;\n label?: string;\n [key: string]: any;\n}\n\n// Variable constructor. A variable is simply a name and a type (can be null).\nexport class Variable<T extends Type = Type> {\n static TYPE = 'variable';\n\n static isInstanceOf(obj: any): obj is Variable {\n return obj instanceof Variable || 'name' in obj;\n }\n\n name: string;\n type: T | null;\n errors: any[];\n label?: string;\n relationship?: string;\n isRelationshipId?: boolean;\n isBelongsToId?: boolean;\n sourceTypeName?: string;\n sourceElement: XMLElement;\n\n constructor(name: string, type: T | null) {\n this.name = name;\n this.type = type;\n this.errors = [];\n }\n\n toJSON() {\n const result: VariableJsonType = {\n name: this.name,\n type: undefined\n };\n if (this.type != null) {\n result.type = this.type.name;\n }\n\n if (typeof this.label != 'undefined') {\n result.label = this.label;\n }\n if (this.type != null && !(this.type instanceof SchemaModelType)) {\n const typeJson = this.type.toJSON();\n Object.assign(result, typeJson);\n }\n\n if (this.relationship != null) {\n result.relationship = this.relationship;\n result.isRelationshipId = this.isRelationshipId;\n }\n\n return result;\n }\n}\n\nexport interface GenerateVariableEvent<T extends Type> extends GenerateTypeEvent {\n name: string;\n type: T;\n}\n\nexport class VariableFactory<T extends Type = Type> extends AbstractObjectTypeFactory<\n Variable<T>,\n GenerateVariableEvent<T>\n> {\n constructor() {\n super(Variable.TYPE);\n }\n generate<T extends Type = Type>(event: GenerateVariableEvent<T>): Variable<T> {\n return new Variable<T>(event.name, event.type);\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BooleanType = void 0;
|
|
4
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
5
|
+
const ChoiceType_1 = require("./ChoiceType");
|
|
6
|
+
class BooleanType extends (0, ChoiceType_1.withChoices)(parser_type_system_1.BooleanType) {
|
|
7
|
+
}
|
|
8
|
+
exports.BooleanType = BooleanType;
|
|
9
|
+
//# sourceMappingURL=Boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Boolean.js","sourceRoot":"","sources":["../../../src/types/primitives/Boolean.ts"],"names":[],"mappings":";;;AAAA,wEAAkF;AAClF,6CAA2C;AAE3C,iBAAyB,SAAQ,IAAA,wBAAW,EAAC,gCAAgB,CAAC;CAAG","sourcesContent":["import { BooleanType as ValueBooleanType } from '@ja-platform/parser-type-system';\nimport { withChoices } from './ChoiceType';\n\nexport class BooleanType extends withChoices(ValueBooleanType) {}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChoiceType = void 0;
|
|
4
|
+
exports.withChoices = withChoices;
|
|
5
|
+
const EnumOption_1 = require("../EnumOption");
|
|
6
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
7
|
+
/**
|
|
8
|
+
* Add schema option labels without replacing the underlying value type.
|
|
9
|
+
*/
|
|
10
|
+
function withChoices(Base) {
|
|
11
|
+
return class extends Base {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.options = {};
|
|
15
|
+
this.multipleOptions = false;
|
|
16
|
+
this.hasOptions = false;
|
|
17
|
+
}
|
|
18
|
+
format(value) {
|
|
19
|
+
var _a;
|
|
20
|
+
var _b;
|
|
21
|
+
if (!this.multipleOptions) {
|
|
22
|
+
return (_b = (_a = this.options[value]) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : '< invalid value >';
|
|
23
|
+
}
|
|
24
|
+
if (value == null || value.length === 0)
|
|
25
|
+
return '';
|
|
26
|
+
const values = Array.prototype.slice.call(value);
|
|
27
|
+
values.sort((a, b) => {
|
|
28
|
+
const left = this.options[a];
|
|
29
|
+
const right = this.options[b];
|
|
30
|
+
return left == null || right == null ? 0 : left.index - right.index;
|
|
31
|
+
});
|
|
32
|
+
return values.map((item) => { var _a; var _b; return (_b = (_a = this.options[item]) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : '< invalid value >'; }).join(', ');
|
|
33
|
+
}
|
|
34
|
+
addOption(value, label, index) {
|
|
35
|
+
if (value in this.options) {
|
|
36
|
+
throw new Error("key '" + value + "' is already used");
|
|
37
|
+
}
|
|
38
|
+
this.options[value] = new EnumOption_1.EnumOption(value, label, index);
|
|
39
|
+
this.hasOptions = true;
|
|
40
|
+
return this.options[value];
|
|
41
|
+
}
|
|
42
|
+
values(obj) {
|
|
43
|
+
return Object.keys(obj).map((key) => {
|
|
44
|
+
return obj[key].toJSON();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return Object.assign(Object.assign({}, super.toJSON()), { options: Object.keys(this.options).map((key) => {
|
|
49
|
+
return this.options[key].toJSON();
|
|
50
|
+
}) });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
class ChoiceType extends withChoices(parser_type_system_1.Type) {
|
|
55
|
+
static isInstanceOf(type) {
|
|
56
|
+
return type != null && 'options' in type && 'addOption' in type;
|
|
57
|
+
}
|
|
58
|
+
constructor(name, config) {
|
|
59
|
+
var _a;
|
|
60
|
+
super(name);
|
|
61
|
+
this.multipleOptions = (_a = config === null || config === void 0 ? void 0 : config.multiple) !== null && _a !== void 0 ? _a : false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ChoiceType = ChoiceType;
|
|
65
|
+
//# sourceMappingURL=ChoiceType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChoiceType.js","sourceRoot":"","sources":["../../../src/types/primitives/ChoiceType.ts"],"names":[],"mappings":";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-system';\n\nexport interface ChoiceTypeConfig {\n multiple: boolean;\n}\n\n/**\n * Add schema option labels without replacing the underlying value type.\n */\nexport function withChoices<TBase extends new (...args: any[]) => Type>(Base: TBase) {\n return class extends Base {\n options: Record<string, EnumOption> = {};\n multipleOptions = false;\n hasOptions = false;\n\n format(value: any): string {\n if (!this.multipleOptions) {\n return this.options[value]?.label ?? '< invalid value >';\n }\n if (value == null || value.length === 0) return '';\n const values: any[] = Array.prototype.slice.call(value);\n values.sort((a, b) => {\n const left = this.options[a];\n const right = this.options[b];\n return left == null || right == null ? 0 : left.index - right.index;\n });\n return values.map((item) => this.options[item]?.label ?? '< invalid value >').join(', ');\n }\n\n addOption(value: any, label: string, index: number): EnumOption {\n if (value in this.options) {\n throw new Error(\"key '\" + value + \"' is already used\");\n }\n this.options[value] = new EnumOption(value, label, index);\n this.hasOptions = true;\n return this.options[value];\n }\n\n values(obj: any) {\n return Object.keys(obj).map((key) => {\n return obj[key].toJSON();\n });\n }\n\n toJSON(): any {\n return {\n ...super.toJSON(),\n options: Object.keys(this.options).map((key) => {\n return this.options[key].toJSON();\n })\n };\n }\n };\n}\n\nexport abstract class ChoiceType extends withChoices(Type) {\n static isInstanceOf(type: Type | null): type is ChoiceType {\n return type != null && 'options' in type && 'addOption' in type;\n }\n\n constructor(name: string, config?: ChoiceTypeConfig) {\n super(name);\n this.multipleOptions = config?.multiple ?? false;\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DateType = void 0;
|
|
7
|
+
const day_1 = require("../../day");
|
|
8
|
+
const moment_1 = __importDefault(require("moment"));
|
|
9
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
10
|
+
class DateType extends parser_type_system_1.Type {
|
|
11
|
+
static isInstanceOf(type) {
|
|
12
|
+
return (type === null || type === void 0 ? void 0 : type._typeName) === DateType.TYPE;
|
|
13
|
+
}
|
|
14
|
+
constructor() {
|
|
15
|
+
super(DateType.TYPE);
|
|
16
|
+
this._typeName = 'date';
|
|
17
|
+
}
|
|
18
|
+
// Return either {} or {isDay: true}.
|
|
19
|
+
// For consistency, we never return {isDay: undefined} or {isDay: false}.
|
|
20
|
+
toJSON() {
|
|
21
|
+
const json = super.toJSON();
|
|
22
|
+
if (this.isDay) {
|
|
23
|
+
json.isDay = true;
|
|
24
|
+
}
|
|
25
|
+
return json;
|
|
26
|
+
}
|
|
27
|
+
format(value, format) {
|
|
28
|
+
// Works for Date and Day objects.
|
|
29
|
+
if (day_1.Day.isDay(value)) {
|
|
30
|
+
value = value.toDate();
|
|
31
|
+
}
|
|
32
|
+
const d = (0, moment_1.default)(value).utc();
|
|
33
|
+
return d.format(format !== null && format !== void 0 ? format : DateType.DEFAULT_FORMAT);
|
|
34
|
+
}
|
|
35
|
+
is(value) {
|
|
36
|
+
return this.isDay ? day_1.Day.isDay(value) : value instanceof Date;
|
|
37
|
+
}
|
|
38
|
+
parse(value) {
|
|
39
|
+
if (this.isDay) {
|
|
40
|
+
if (day_1.Day.isDay(value)) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
else if (value instanceof Date) {
|
|
44
|
+
// Convert from local timezone
|
|
45
|
+
return new day_1.Day(value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error(value + ' is not a Day');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (value instanceof Date) {
|
|
53
|
+
// Assume UTC timezone
|
|
54
|
+
return (0, day_1.pureDate)(value);
|
|
55
|
+
}
|
|
56
|
+
else if (day_1.Day.isDay(value)) {
|
|
57
|
+
return value.toDate();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new Error(value + ' is not a Date');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.DateType = DateType;
|
|
66
|
+
DateType.DEFAULT_FORMAT = 'MMMM D YYYY';
|
|
67
|
+
DateType.TYPE = 'date';
|
|
68
|
+
//# sourceMappingURL=Date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Date.js","sourceRoot":"","sources":["../../../src/types/primitives/Date.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA0C;AAC1C,oDAA4B;AAC5B,wEAAuD;AAEvD,cAAsB,SAAQ,yBAAI;IAKhC,MAAM,CAAC,YAAY,CAAC,IAAiB;QACnC,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,MAAK,QAAQ,CAAC,IAAI,CAAC;IAC3C,CAAC;IAGD;QACE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QATd,cAAS,GAAG,MAAM,CAAC;IAU5B,CAAC;IAED,qCAAqC;IACrC,yEAAyE;IACzE,MAAM;QACJ,MAAM,IAAI,GAAwB,KAAK,CAAC,MAAM,EAAE,CAAC;QACjD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,KAAU,EAAE,MAAe;QAChC,kCAAkC;QAClC,IAAI,SAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QACzB,CAAC;QACD,MAAM,CAAC,GAAG,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,QAAQ,CAAC,cAAc,CAAC,CAAC;IACrD,CAAC;IAED,EAAE,CAAC,KAAU;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,KAAU;QACd,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,SAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrB,OAAO,KAAK,CAAC;YACf,CAAC;iBAAM,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;gBACjC,8BAA8B;gBAC9B,OAAO,IAAI,SAAG,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,KAAK,GAAG,eAAe,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;gBAC1B,sBAAsB;gBACtB,OAAO,IAAA,cAAQ,EAAC,KAAK,CAAC,CAAC;YACzB,CAAC;iBAAM,IAAI,SAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5B,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;IACH,CAAC;CACF;;AAxDQ,uBAAc,GAAG,aAAa,AAAhB,CAAiB;AAEtB,aAAI,GAAG,MAAM,AAAT,CAAU","sourcesContent":["import { Day, pureDate } from '../../day';\nimport moment from 'moment';\nimport { Type } from '@ja-platform/parser-type-system';\n\nexport class DateType extends Type {\n static DEFAULT_FORMAT = 'MMMM D YYYY';\n readonly _typeName = 'date';\n static readonly TYPE = 'date';\n\n static isInstanceOf(type: Type | null): type is DateType {\n return type?._typeName === DateType.TYPE;\n }\n isDay?: boolean;\n\n constructor() {\n super(DateType.TYPE);\n }\n\n // Return either {} or {isDay: true}.\n // For consistency, we never return {isDay: undefined} or {isDay: false}.\n toJSON(): any {\n const json: { isDay?: boolean } = super.toJSON();\n if (this.isDay) {\n json.isDay = true;\n }\n return json;\n }\n format(value: any, format?: string) {\n // Works for Date and Day objects.\n if (Day.isDay(value)) {\n value = value.toDate();\n }\n const d = moment(value).utc();\n return d.format(format ?? DateType.DEFAULT_FORMAT);\n }\n\n is(value: any): boolean {\n return this.isDay ? Day.isDay(value) : value instanceof Date;\n }\n\n parse(value: any) {\n if (this.isDay) {\n if (Day.isDay(value)) {\n return value;\n } else if (value instanceof Date) {\n // Convert from local timezone\n return new Day(value);\n } else {\n throw new Error(value + ' is not a Day');\n }\n } else {\n if (value instanceof Date) {\n // Assume UTC timezone\n return pureDate(value);\n } else if (Day.isDay(value)) {\n return value.toDate();\n } else {\n throw new Error(value + ' is not a Date');\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DatetimeType = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
9
|
+
class DatetimeType extends parser_type_system_1.Type {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(DatetimeType.TYPE);
|
|
12
|
+
}
|
|
13
|
+
format(value, format) {
|
|
14
|
+
return (0, moment_1.default)(value).format(format !== null && format !== void 0 ? format : DatetimeType.DEFAULT_FORMAT);
|
|
15
|
+
}
|
|
16
|
+
is(value) {
|
|
17
|
+
return value instanceof Date;
|
|
18
|
+
}
|
|
19
|
+
parse(value) {
|
|
20
|
+
if (value instanceof Date) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(value + ' is not a Date');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.DatetimeType = DatetimeType;
|
|
29
|
+
DatetimeType.DEFAULT_FORMAT = 'MMMM D YYYY h:mm A';
|
|
30
|
+
DatetimeType.TYPE = 'datetime';
|
|
31
|
+
//# sourceMappingURL=Datetime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Datetime.js","sourceRoot":"","sources":["../../../src/types/primitives/Datetime.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,wEAAuD;AAEvD,kBAA0B,SAAQ,yBAAI;IAIpC;QACE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,MAAM,CAAC,KAAU,EAAE,MAAe;QAChC,OAAO,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,YAAY,CAAC,cAAc,CAAC,CAAC;IACrE,CAAC;IAED,EAAE,CAAC,KAAU;QACX,OAAO,KAAK,YAAY,IAAI,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,KAAU;QACd,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;;AArBQ,2BAAc,GAAG,oBAAoB,CAAC;AAC7B,iBAAI,GAAG,UAAU,CAAC","sourcesContent":["import moment from 'moment';\nimport { Type } from '@ja-platform/parser-type-system';\n\nexport class DatetimeType extends Type {\n static DEFAULT_FORMAT = 'MMMM D YYYY h:mm A';\n static readonly TYPE = 'datetime';\n\n constructor() {\n super(DatetimeType.TYPE);\n }\n format(value: any, format?: string): string {\n return moment(value).format(format ?? DatetimeType.DEFAULT_FORMAT);\n }\n\n is(value: any): boolean {\n return value instanceof Date;\n }\n\n parse(value: any): any {\n if (value instanceof Date) {\n return value;\n } else {\n throw new Error(value + ' is not a Date');\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeoTrackType = void 0;
|
|
4
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
5
|
+
class GeoTrackType extends parser_type_system_1.Type {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(GeoTrackType.TYPE);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.GeoTrackType = GeoTrackType;
|
|
11
|
+
GeoTrackType.TYPE = 'track';
|
|
12
|
+
//# sourceMappingURL=GeoTrack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeoTrack.js","sourceRoot":"","sources":["../../../src/types/primitives/GeoTrack.ts"],"names":[],"mappings":";;;AAAA,wEAAuD;AAEvD,kBAA0B,SAAQ,yBAAI;IAGpC;QACE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF;;AALiB,iBAAI,GAAG,OAAO,CAAC","sourcesContent":["import { Type } from '@ja-platform/parser-type-system';\n\nexport class GeoTrackType extends Type {\n static readonly TYPE = 'track';\n\n constructor() {\n super(GeoTrackType.TYPE);\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocationType = void 0;
|
|
4
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
5
|
+
const Text_1 = require("./Text");
|
|
6
|
+
class LocationType extends parser_type_system_1.ObjectType {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(LocationType.TYPE);
|
|
9
|
+
}
|
|
10
|
+
getField(name) {
|
|
11
|
+
return ['latitude', 'longitude', 'altitude', 'horizontal_accuracy', 'vertical_accuracy'].includes(name)
|
|
12
|
+
? new Text_1.TextType()
|
|
13
|
+
: null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.LocationType = LocationType;
|
|
17
|
+
LocationType.TYPE = 'location';
|
|
18
|
+
//# sourceMappingURL=Location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Location.js","sourceRoot":"","sources":["../../../src/types/primitives/Location.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AACnE,iCAAkC;AAElC,kBAA0B,SAAQ,+BAAU;IAG1C;QACE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,OAAO,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,EAAE,mBAAmB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YACrG,CAAC,CAAC,IAAI,eAAQ,EAAE;YAChB,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;CACF;;AAXiB,iBAAI,GAAG,UAAU,CAAC","sourcesContent":["import { ObjectType, Type } from '@ja-platform/parser-type-system';\nimport { TextType } from './Text';\n\nexport class LocationType extends ObjectType {\n static readonly TYPE = 'location';\n\n constructor() {\n super(LocationType.TYPE);\n }\n\n getField(name: string): Type | null {\n return ['latitude', 'longitude', 'altitude', 'horizontal_accuracy', 'vertical_accuracy'].includes(name)\n ? new TextType()\n : null;\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultipleChoiceType = void 0;
|
|
4
|
+
const ChoiceType_1 = require("./ChoiceType");
|
|
5
|
+
class MultipleChoiceType extends ChoiceType_1.ChoiceType {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(MultipleChoiceType.TYPE, { multiple: true });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.MultipleChoiceType = MultipleChoiceType;
|
|
11
|
+
MultipleChoiceType.TYPE = 'multiple-choice';
|
|
12
|
+
//# sourceMappingURL=MultipleChoice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultipleChoice.js","sourceRoot":"","sources":["../../../src/types/primitives/MultipleChoice.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,wBAAgC,SAAQ,uBAAU;IAGhD;QACE,KAAK,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;CACF;;AALiB,uBAAI,GAAG,iBAAiB,CAAC","sourcesContent":["import { ChoiceType } from './ChoiceType';\n\nexport class MultipleChoiceType extends ChoiceType {\n static readonly TYPE = 'multiple-choice';\n\n constructor() {\n super(MultipleChoiceType.TYPE, { multiple: true });\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultipleChoiceIntegerType = void 0;
|
|
4
|
+
const ChoiceType_1 = require("./ChoiceType");
|
|
5
|
+
class MultipleChoiceIntegerType extends ChoiceType_1.ChoiceType {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(MultipleChoiceIntegerType.TYPE, { multiple: true });
|
|
8
|
+
}
|
|
9
|
+
setOptionLabels(labels) {
|
|
10
|
+
this.options = {};
|
|
11
|
+
for (let i = 0; i < labels.length; i++) {
|
|
12
|
+
this.addOption(i, labels[i], i);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
is(value) {
|
|
16
|
+
return Array.isArray(value) && value.every((item) => this.options[item] != null);
|
|
17
|
+
}
|
|
18
|
+
parse(value) {
|
|
19
|
+
if (!(value instanceof Array)) {
|
|
20
|
+
throw new Error(value + ' is not an array');
|
|
21
|
+
}
|
|
22
|
+
for (let i = 0; i < value.length; i++) {
|
|
23
|
+
const index = value[i];
|
|
24
|
+
const option = this.options[index];
|
|
25
|
+
if (option == null) {
|
|
26
|
+
throw new Error(index + ' is not a valid option');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.MultipleChoiceIntegerType = MultipleChoiceIntegerType;
|
|
33
|
+
MultipleChoiceIntegerType.TYPE = 'multiple-choice-integer';
|
|
34
|
+
//# sourceMappingURL=MultipleChoiceInteger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultipleChoiceInteger.js","sourceRoot":"","sources":["../../../src/types/primitives/MultipleChoiceInteger.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,+BAAuC,SAAQ,uBAAU;IAGvD;QACE,KAAK,CAAC,yBAAyB,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,eAAe,CAAC,MAAgB;QAC9B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,EAAE,CAAC,KAAU;QACX,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;IACnF,CAAC;IAED,KAAK,CAAC,KAAU;QACd,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,KAAK,GAAG,kBAAkB,CAAC,CAAC;QAC9C,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACvB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,KAAK,GAAG,wBAAwB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;;AAhCiB,8BAAI,GAAG,yBAAyB,CAAC","sourcesContent":["import { ChoiceType } from './ChoiceType';\n\nexport class MultipleChoiceIntegerType extends ChoiceType {\n static readonly TYPE = 'multiple-choice-integer';\n\n constructor() {\n super(MultipleChoiceIntegerType.TYPE, { multiple: true });\n }\n\n setOptionLabels(labels: string[]) {\n this.options = {};\n for (let i = 0; i < labels.length; i++) {\n this.addOption(i, labels[i], i);\n }\n }\n\n is(value: any): boolean {\n return Array.isArray(value) && value.every((item) => this.options[item] != null);\n }\n\n parse(value: any) {\n if (!(value instanceof Array)) {\n throw new Error(value + ' is not an array');\n }\n\n for (let i = 0; i < value.length; i++) {\n const index = value[i];\n const option = this.options[index];\n if (option == null) {\n throw new Error(index + ' is not a valid option');\n }\n }\n\n return value;\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleChoiceType = void 0;
|
|
4
|
+
const ChoiceType_1 = require("./ChoiceType");
|
|
5
|
+
class SingleChoiceType extends ChoiceType_1.ChoiceType {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(SingleChoiceType.TYPE, { multiple: false });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.SingleChoiceType = SingleChoiceType;
|
|
11
|
+
SingleChoiceType.TYPE = 'single-choice';
|
|
12
|
+
//# sourceMappingURL=SingleChoice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SingleChoice.js","sourceRoot":"","sources":["../../../src/types/primitives/SingleChoice.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,sBAA8B,SAAQ,uBAAU;IAG9C;QACE,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC;CACF;;AALiB,qBAAI,GAAG,eAAe,CAAC","sourcesContent":["import { ChoiceType } from './ChoiceType';\n\nexport class SingleChoiceType extends ChoiceType {\n static readonly TYPE = 'single-choice';\n\n constructor() {\n super(SingleChoiceType.TYPE, { multiple: false });\n }\n}\n"]}
|