@snowplow/snowtype-core 0.1.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.
Files changed (60) hide show
  1. package/LICENSE +57 -0
  2. package/dist/index.d.ts +21 -0
  3. package/dist/index.js +10 -0
  4. package/dist/json-schema-to-jsdoc/index.d.ts +1 -0
  5. package/dist/json-schema-to-jsdoc/index.js +231 -0
  6. package/dist/languages/go.d.ts +18 -0
  7. package/dist/languages/go.js +61 -0
  8. package/dist/languages/index.d.ts +40 -0
  9. package/dist/languages/index.js +42 -0
  10. package/dist/languages/javascript.d.ts +2 -0
  11. package/dist/languages/javascript.js +117 -0
  12. package/dist/languages/kotlin.d.ts +1 -0
  13. package/dist/languages/kotlin.js +97 -0
  14. package/dist/languages/precompiled-templates/go/go.d.ts +10 -0
  15. package/dist/languages/precompiled-templates/go/go.js +110 -0
  16. package/dist/languages/precompiled-templates/index.d.ts +124 -0
  17. package/dist/languages/precompiled-templates/index.js +61 -0
  18. package/dist/languages/precompiled-templates/javascript/browser-tracker.d.ts +10 -0
  19. package/dist/languages/precompiled-templates/javascript/browser-tracker.js +107 -0
  20. package/dist/languages/precompiled-templates/javascript/javascript-tracker.d.ts +10 -0
  21. package/dist/languages/precompiled-templates/javascript/javascript-tracker.js +107 -0
  22. package/dist/languages/precompiled-templates/javascript/node-tracker.d.ts +10 -0
  23. package/dist/languages/precompiled-templates/javascript/node-tracker.js +107 -0
  24. package/dist/languages/precompiled-templates/kotlin/kotlin.d.ts +57 -0
  25. package/dist/languages/precompiled-templates/kotlin/kotlin.js +569 -0
  26. package/dist/languages/precompiled-templates/swift/swift.d.ts +46 -0
  27. package/dist/languages/precompiled-templates/swift/swift.js +474 -0
  28. package/dist/languages/precompiled-templates/typescript/browser-tracker.d.ts +10 -0
  29. package/dist/languages/precompiled-templates/typescript/browser-tracker.js +87 -0
  30. package/dist/languages/precompiled-templates/typescript/node-tracker.d.ts +11 -0
  31. package/dist/languages/precompiled-templates/typescript/node-tracker.js +97 -0
  32. package/dist/languages/swift.d.ts +17 -0
  33. package/dist/languages/swift.js +90 -0
  34. package/dist/languages/types.d.ts +69 -0
  35. package/dist/languages/types.js +2 -0
  36. package/dist/languages/typescript.d.ts +2 -0
  37. package/dist/languages/typescript.js +64 -0
  38. package/dist/quicktype/generator.d.ts +11 -0
  39. package/dist/quicktype/generator.js +99 -0
  40. package/dist/quicktype/handlebars-helpers.d.ts +1 -0
  41. package/dist/quicktype/handlebars-helpers.js +29 -0
  42. package/dist/quicktype/index.d.ts +43 -0
  43. package/dist/quicktype/index.js +39 -0
  44. package/dist/quicktype/metadata.d.ts +15 -0
  45. package/dist/quicktype/metadata.js +27 -0
  46. package/dist/quicktype/quicktype-utils.d.ts +59 -0
  47. package/dist/quicktype/quicktype-utils.js +140 -0
  48. package/dist/quicktype/renderer-helpers.d.ts +8 -0
  49. package/dist/quicktype/renderer-helpers.js +38 -0
  50. package/dist/quicktype/templates.d.ts +12 -0
  51. package/dist/quicktype/templates.js +68 -0
  52. package/dist/quicktype/utils.d.ts +8 -0
  53. package/dist/quicktype/utils.js +27 -0
  54. package/dist/test/index.test.d.ts +1 -0
  55. package/dist/test/index.test.js +33 -0
  56. package/dist/test/mocks/input.d.ts +285 -0
  57. package/dist/test/mocks/input.js +425 -0
  58. package/dist/utils/index.d.ts +6 -0
  59. package/dist/utils/index.js +10 -0
  60. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,57 @@
1
+ # Snowplow Personal & Academic License Agreement
2
+
3
+ _Version 1.0, September 2023_
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it, but only for any non-commercial purpose.
12
+
13
+ Non-commercial purposes include only:
14
+
15
+ * Personal use for research, experiment, personal study, or hobby projects, without any anticipated commercial application.
16
+ * Use for teaching purposes by lecturers of a school or university.
17
+ * Use to evaluate the sufficiency of the software for the commercial needs of you or your company.
18
+
19
+ ## Notices
20
+
21
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above.
22
+
23
+ ## Patent License
24
+
25
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software for a non-commercial purpose.
26
+
27
+ ## Fair Use
28
+
29
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
30
+
31
+ ## No Other Rights
32
+
33
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
34
+
35
+ ## Patent Defense
36
+
37
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
38
+
39
+ ## Violations
40
+
41
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
42
+
43
+ ## No Liability
44
+
45
+ **As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.**
46
+
47
+ ## Definitions
48
+
49
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
50
+
51
+ **You** refers to the individual or entity agreeing to these terms.
52
+
53
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
54
+
55
+ **Your licenses** are all the licenses granted to you for the software under these terms.
56
+
57
+ **Use** means anything you do with the software requiring one of your licenses.
@@ -0,0 +1,21 @@
1
+ import { LanguageIds, TrackerTemplates } from "./languages";
2
+ export type { LanguageIds, TrackerTemplates };
3
+ export type ScenarioIdentifiers = {
4
+ name: string;
5
+ id: string;
6
+ };
7
+ export type DataProduct = {
8
+ scenario: ScenarioIdentifiers;
9
+ eventSchema: Schema;
10
+ entitiesSchemas?: Schema[];
11
+ };
12
+ export type Schema = {
13
+ [k: string]: unknown;
14
+ };
15
+ export type GenerationInput = {
16
+ language: LanguageIds;
17
+ tracker: TrackerTemplates;
18
+ dataProducts: DataProduct[];
19
+ schemas: Schema[];
20
+ };
21
+ export declare function generate(input: GenerationInput): Promise<import("quicktype-core").SerializedRenderResult> | undefined;
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = void 0;
4
+ const languages_1 = require("./languages");
5
+ const FILE_HEADER = ["Automatically generated by Snowtype"];
6
+ function generate(input) {
7
+ const selectedLanguageGenerator = languages_1.supportedLanguages.find((lang) => lang.id === input.language);
8
+ return selectedLanguageGenerator === null || selectedLanguageGenerator === void 0 ? void 0 : selectedLanguageGenerator.generate(input.schemas, input.dataProducts, Object.assign({ header: FILE_HEADER, outputFilename: "snowplow", tracker: input.tracker }, {}));
9
+ }
10
+ exports.generate = generate;
@@ -0,0 +1 @@
1
+ export declare function generate(schema: any, options?: {}): string;
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ /* npm json-schema-to-jsdoc */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.generate = void 0;
8
+ // @ts-nocheck
9
+ const json_pointer_1 = __importDefault(require("json-pointer"));
10
+ function getDefaultPropertyType({ propertyNameAsType, capitalizeProperty, defaultPropertyType }, property) {
11
+ const fallbackPropertyType = '*';
12
+ if (property !== undefined && propertyNameAsType) {
13
+ return capitalizeProperty ? upperFirst(property) : property;
14
+ }
15
+ if (defaultPropertyType === null || defaultPropertyType === '') {
16
+ return defaultPropertyType;
17
+ }
18
+ return defaultPropertyType || fallbackPropertyType;
19
+ }
20
+ function wrapDescription(config, description) {
21
+ const { maxLength } = config;
22
+ if (!maxLength) {
23
+ return [description];
24
+ }
25
+ const result = [];
26
+ while (true) {
27
+ const excess = description.length - config.indentMaxDelta;
28
+ if (excess <= 0) {
29
+ if (description) {
30
+ result.push(description);
31
+ }
32
+ break;
33
+ }
34
+ const maxLine = description.slice(0, config.indentMaxDelta);
35
+ const wsIndex = maxLine.search(/\s\S*$/);
36
+ let safeString;
37
+ if (wsIndex === -1) {
38
+ // With this being all non-whitespace, e.g., a long link, we
39
+ // let it go on without wrapping until whitespace is reached
40
+ const remainder = description.slice(config.indentMaxDelta).match(/^\S+/);
41
+ safeString = maxLine + (remainder || '');
42
+ }
43
+ else {
44
+ safeString = maxLine.slice(0, wsIndex);
45
+ }
46
+ result.push(safeString);
47
+ description = description.slice(safeString.length + 1);
48
+ }
49
+ return result;
50
+ }
51
+ function generate(schema, options = {}) {
52
+ const jsdoc = [];
53
+ if (!schema || Object.keys(schema).length === 0) {
54
+ return '';
55
+ }
56
+ const config = parseOptions(options);
57
+ jsdoc.push(...writeDescription(schema, config));
58
+ if (json_pointer_1.default.has(schema, '/properties')) {
59
+ jsdoc.push(...processProperties(schema, schema, null, config));
60
+ }
61
+ if (json_pointer_1.default.has(schema, '/items')) {
62
+ jsdoc.push(...processItems(schema, schema, null, config));
63
+ }
64
+ return format(config.outerIndent, jsdoc);
65
+ }
66
+ exports.generate = generate;
67
+ function parseOptions(options) {
68
+ const asteriskAndWhitespaceLength = 3; // ' * '
69
+ const outerIndent = (options.indentChar || ' ').repeat(options.indent || 0);
70
+ const indentMaxDelta = options.maxLength - outerIndent.length -
71
+ asteriskAndWhitespaceLength;
72
+ return Object.assign(Object.assign({}, options), { outerIndent,
73
+ indentMaxDelta });
74
+ }
75
+ function processItems(schema, rootSchema, base, config) {
76
+ const items = json_pointer_1.default.get(schema, '/items');
77
+ if (!Array.isArray(items)) {
78
+ return [];
79
+ }
80
+ const result = [];
81
+ items.forEach((item, i) => {
82
+ const root = base ? `${base}.` : '';
83
+ const prefixedProperty = root + i;
84
+ const defaultValue = item.default;
85
+ const optional = !schema.minItems || i >= schema.minItems;
86
+ if (item.type === 'array' && item.items) {
87
+ result.push(...writeProperty('array', prefixedProperty, item.description, optional, defaultValue, config));
88
+ result.push(...processItems(item, rootSchema, prefixedProperty, config));
89
+ }
90
+ else if (item.type === 'object' && item.properties) {
91
+ result.push(...writeProperty('object', prefixedProperty, item.description, optional, defaultValue, config));
92
+ result.push(...processProperties(item, rootSchema, prefixedProperty, config));
93
+ }
94
+ else {
95
+ const type = getType(item, rootSchema) || getDefaultPropertyType(config);
96
+ result.push(...writeProperty(type, prefixedProperty, item.description, optional, defaultValue, config));
97
+ }
98
+ });
99
+ return result;
100
+ }
101
+ function processProperties(schema, rootSchema, base, config) {
102
+ const props = json_pointer_1.default.get(schema, '/properties');
103
+ const required = json_pointer_1.default.has(schema, '/required') ? json_pointer_1.default.get(schema, '/required') : [];
104
+ const result = [];
105
+ for (const property in props) {
106
+ if (Array.isArray(config.ignore) && config.ignore.includes(property)) {
107
+ continue;
108
+ }
109
+ else {
110
+ const prop = props[property];
111
+ const root = base ? `${base}.` : '';
112
+ const prefixedProperty = root + property;
113
+ const defaultValue = props[property].default;
114
+ const optional = !required.includes(property);
115
+ if (prop.type === 'object' && prop.properties) {
116
+ result.push(...writeProperty('object', prefixedProperty, prop.description, optional, defaultValue, config));
117
+ result.push(...processProperties(prop, rootSchema, prefixedProperty, config));
118
+ }
119
+ else if (prop.type === 'array' && prop.items) {
120
+ result.push(...writeProperty('array', prefixedProperty, prop.description, optional, defaultValue, config));
121
+ result.push(...processItems(prop, rootSchema, prefixedProperty, config));
122
+ }
123
+ else {
124
+ const type = getType(prop, rootSchema) || getDefaultPropertyType(config, property);
125
+ result.push(...writeProperty(type, prefixedProperty, prop.description, optional, defaultValue, config));
126
+ }
127
+ }
128
+ }
129
+ return result;
130
+ }
131
+ function writeDescription(schema, config) {
132
+ const result = [];
133
+ const { objectTagName = 'typedef' } = config;
134
+ let { description } = schema;
135
+ if (description === undefined) {
136
+ description = config.autoDescribe ? generateDescription(schema.title, schema.type) : '';
137
+ }
138
+ const typeMatch = config.types && config.types[schema.type];
139
+ let type;
140
+ if (config.types === null) {
141
+ type = '';
142
+ }
143
+ else {
144
+ type = ` {${typeMatch === ''
145
+ ? ''
146
+ : typeMatch || getType(schema, schema)}}`;
147
+ }
148
+ if (description || config.addDescriptionLineBreak) {
149
+ result.push(...wrapDescription(config, description));
150
+ }
151
+ const namepath = schema.title ? ` ${config.capitalizeTitle ? upperFirst(schema.title) : schema.title}` : '';
152
+ result.push(`@${objectTagName}${type}${namepath}`);
153
+ return result;
154
+ }
155
+ function writeProperty(type, field, description = '', optional, defaultValue, config) {
156
+ let fieldTemplate;
157
+ if (optional) {
158
+ fieldTemplate = `[${field}${defaultValue === undefined ? '' : `=${JSON.stringify(defaultValue)}`}]`;
159
+ }
160
+ else {
161
+ fieldTemplate = field;
162
+ }
163
+ let desc;
164
+ if (!description && !config.descriptionPlaceholder) {
165
+ desc = '';
166
+ }
167
+ else if (config.hyphenatedDescriptions) {
168
+ desc = ` - ${description}`;
169
+ }
170
+ else {
171
+ desc = ` ${description}`;
172
+ }
173
+ const typeExpression = type === null ? '' : `{${type}} `;
174
+ return wrapDescription(config, `@property ${typeExpression}${fieldTemplate}${desc}`);
175
+ }
176
+ function getType(schema, rootSchema) {
177
+ if (schema.$ref) {
178
+ const ref = json_pointer_1.default.get(rootSchema, schema.$ref.slice(1));
179
+ return getType(ref, rootSchema);
180
+ }
181
+ if (schema.enum) {
182
+ /* Try to autodetect schema type */
183
+ if (!schema.type) {
184
+ // TODO, add condition for enum values with null as option
185
+ if (typeof schema.enum[0] === "string") {
186
+ schema.type = 'string';
187
+ }
188
+ if ((typeof schema.enum[0]).match(/number|boolean/)) {
189
+ schema.type = 'number';
190
+ }
191
+ }
192
+ // Try to detect the case of type: ["string", "null"]
193
+ // enum could be ["foo", "bar", null]
194
+ if (Array.isArray(schema.type)) {
195
+ if (schema.type.indexOf('string') !== -1 && schema.type.indexOf('null') !== -1) {
196
+ return `"${schema.enum.filter(Boolean).join('"|"')}"|null`;
197
+ }
198
+ }
199
+ if (schema.type === 'string') {
200
+ return `"${schema.enum.join('"|"')}"`;
201
+ }
202
+ if (schema.type === 'number' || schema.type === 'integer' ||
203
+ schema.type === 'boolean') {
204
+ return `${schema.enum.join('|')}`;
205
+ }
206
+ return schema.type === 'null' ? 'null' : 'enum';
207
+ }
208
+ if (Array.isArray(schema.type)) {
209
+ if (schema.type.includes('null')) {
210
+ return `?${schema.type[0]}`;
211
+ }
212
+ else {
213
+ return schema.type.join('|');
214
+ }
215
+ }
216
+ return schema.type;
217
+ }
218
+ function upperFirst(str) {
219
+ return str.slice(0, 1).toUpperCase() + str.slice(1);
220
+ }
221
+ function generateDescription(title, type) {
222
+ const noun = title ? `${title} ${type}` : type;
223
+ const article = `a${'aeiou'.split('').includes(noun.charAt()) ? 'n' : ''}`;
224
+ return `Represents ${article} ${noun}`;
225
+ }
226
+ function format(outerIndent, lines) {
227
+ const result = [`${outerIndent}/**`];
228
+ result.push(...lines.map(line => line ? `${outerIndent} * ${line}` : ' *'));
229
+ result.push(`${outerIndent} */\n`);
230
+ return result.join('\n');
231
+ }
@@ -0,0 +1,18 @@
1
+ import { LanguageGenerator, QuicktypeSnowtypeSettings } from "./types";
2
+ import { GoRenderer, GoTargetLanguage, Name, OptionValues, RenderContext, TargetLanguage, Type } from "quicktype-core";
3
+ declare class SnowTypeGoRenderer extends GoRenderer {
4
+ protected readonly snowtypeOptions: QuicktypeSnowtypeSettings;
5
+ constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, typescriptOptions: OptionValues<any>, snowtypeOptions: QuicktypeSnowtypeSettings);
6
+ emitSource(givenOutputFilename: string): void;
7
+ makeNameForTopLevel(t: Type, givenName: string, maybeNamedType: Type | undefined): Name;
8
+ }
9
+ export declare class SnowtypeGoLanguage extends GoTargetLanguage {
10
+ protected readonly snowtypeOptions: QuicktypeSnowtypeSettings;
11
+ constructor(snowtypeOptions: QuicktypeSnowtypeSettings);
12
+ protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
13
+ [name: string]: any;
14
+ }): SnowTypeGoRenderer;
15
+ }
16
+ export declare const goBase: LanguageGenerator;
17
+ export declare const go: LanguageGenerator;
18
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.go = exports.goBase = exports.SnowtypeGoLanguage = void 0;
13
+ const quicktype_utils_1 = require("../quicktype/quicktype-utils");
14
+ const quicktype_core_1 = require("quicktype-core");
15
+ const quicktype_1 = require("../quicktype");
16
+ const Strings_1 = require("quicktype-core/dist/support/Strings");
17
+ class SnowTypeGoRenderer extends quicktype_core_1.GoRenderer {
18
+ constructor(targetLanguage, renderContext, typescriptOptions, snowtypeOptions) {
19
+ super(targetLanguage, renderContext, typescriptOptions);
20
+ this.snowtypeOptions = snowtypeOptions;
21
+ }
22
+ emitSource(givenOutputFilename) {
23
+ super.emitSource(givenOutputFilename);
24
+ (0, quicktype_utils_1.executeRenderPlan)(this, this.snowtypeOptions.generators);
25
+ }
26
+ makeNameForTopLevel(t, givenName, maybeNamedType) {
27
+ return (0, quicktype_utils_1.makeNameForTopLevelWithPrefixAndSuffix)((...args) => {
28
+ return super.makeNameForTopLevel(...args);
29
+ }, this.snowtypeOptions, t, givenName, maybeNamedType);
30
+ }
31
+ }
32
+ class SnowtypeGoLanguage extends quicktype_core_1.GoTargetLanguage {
33
+ constructor(snowtypeOptions) {
34
+ super();
35
+ this.snowtypeOptions = snowtypeOptions;
36
+ }
37
+ makeRenderer(renderContext, untypedOptionValues) {
38
+ return new SnowTypeGoRenderer(this, renderContext, (0, quicktype_core_1.getOptionValues)(quicktype_core_1.goOptions, untypedOptionValues), this.snowtypeOptions);
39
+ }
40
+ }
41
+ exports.SnowtypeGoLanguage = SnowtypeGoLanguage;
42
+ exports.goBase = (0, quicktype_1.createQuicktypeLanguageGenerator)({
43
+ name: "go",
44
+ quicktypeLanguage: SnowtypeGoLanguage,
45
+ defaultOptions: {
46
+ "just-types": true,
47
+ "just-types-and-package": true,
48
+ "package": "main",
49
+ "multi-file-output": false,
50
+ "field-tags": "mapstructure",
51
+ },
52
+ nameModifiers: {
53
+ functionName: Strings_1.camelCase,
54
+ },
55
+ });
56
+ exports.go = Object.assign(Object.assign({}, exports.goBase), { generate: (schemaRepositories, dataProducts, options) => __awaiter(void 0, void 0, void 0, function* () {
57
+ // @ts-expect-error
58
+ const { sdk, prefixes, suffixes } = options;
59
+ const result = yield exports.goBase.generate(schemaRepositories, dataProducts, options);
60
+ return result;
61
+ }) });
@@ -0,0 +1,40 @@
1
+ import { LanguageGenerator } from './types';
2
+ export * from './types';
3
+ export { typescript } from './typescript';
4
+ export { javascript } from './javascript';
5
+ export { kotlin } from './kotlin';
6
+ export { swift } from './swift';
7
+ export { go, SnowtypeGoLanguage } from './go';
8
+ export type LanguageIds = "typescript" | "javascript" | "kotlin" | "swift" | "go";
9
+ export interface TrackingScenario {
10
+ id?: string;
11
+ version?: number;
12
+ status?: "draft" | "published" | "deprecated";
13
+ name: string;
14
+ description?: string;
15
+ owner?: string;
16
+ triggers?: string[];
17
+ appIds?: string[];
18
+ event: {
19
+ source: string;
20
+ schema?: unknown;
21
+ [k: string]: unknown;
22
+ };
23
+ entities?: {
24
+ tracked?: {
25
+ source: string;
26
+ minCardinality?: number;
27
+ maxCardinality?: number;
28
+ [k: string]: unknown;
29
+ }[];
30
+ enriched?: {
31
+ source: string;
32
+ minCardinality?: number;
33
+ maxCardinality?: number;
34
+ [k: string]: unknown;
35
+ }[];
36
+ [k: string]: unknown;
37
+ };
38
+ [k: string]: unknown;
39
+ }
40
+ export declare const supportedLanguages: LanguageGenerator[];
@@ -0,0 +1,42 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.supportedLanguages = exports.SnowtypeGoLanguage = exports.go = exports.swift = exports.kotlin = exports.javascript = exports.typescript = void 0;
18
+ const javascript_1 = require("./javascript");
19
+ const kotlin_1 = require("./kotlin");
20
+ const swift_1 = require("./swift");
21
+ const typescript_1 = require("./typescript");
22
+ const go_1 = require("./go");
23
+ __exportStar(require("./types"), exports);
24
+ // Export all your languages here
25
+ var typescript_2 = require("./typescript");
26
+ Object.defineProperty(exports, "typescript", { enumerable: true, get: function () { return typescript_2.typescript; } });
27
+ var javascript_2 = require("./javascript");
28
+ Object.defineProperty(exports, "javascript", { enumerable: true, get: function () { return javascript_2.javascript; } });
29
+ var kotlin_2 = require("./kotlin");
30
+ Object.defineProperty(exports, "kotlin", { enumerable: true, get: function () { return kotlin_2.kotlin; } });
31
+ var swift_2 = require("./swift");
32
+ Object.defineProperty(exports, "swift", { enumerable: true, get: function () { return swift_2.swift; } });
33
+ var go_2 = require("./go");
34
+ Object.defineProperty(exports, "go", { enumerable: true, get: function () { return go_2.go; } });
35
+ Object.defineProperty(exports, "SnowtypeGoLanguage", { enumerable: true, get: function () { return go_2.SnowtypeGoLanguage; } });
36
+ exports.supportedLanguages = [
37
+ typescript_1.typescript,
38
+ javascript_1.javascript,
39
+ kotlin_1.kotlin,
40
+ swift_1.swift,
41
+ go_1.go
42
+ ];
@@ -0,0 +1,2 @@
1
+ import { LanguageGenerator } from "./types";
2
+ export declare const javascript: LanguageGenerator;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.javascript = void 0;
13
+ const quicktype_utils_1 = require("../quicktype/quicktype-utils");
14
+ const quicktype_core_1 = require("quicktype-core");
15
+ const quicktype_1 = require("../quicktype");
16
+ const metadata_1 = require("../quicktype/metadata");
17
+ // @ts-ignore
18
+ const json_schema_to_jsdoc_1 = require("../json-schema-to-jsdoc");
19
+ const Strings_1 = require("quicktype-core/dist/support/Strings");
20
+ class SnowtypeJavaScriptRenderer extends quicktype_core_1.JavaScriptRenderer {
21
+ constructor(targetLanguage, renderContext, typescriptOptions, snowtypeOptions) {
22
+ super(targetLanguage, renderContext, typescriptOptions);
23
+ this.snowtypeOptions = snowtypeOptions;
24
+ }
25
+ emitMultiline(linesString) {
26
+ (0, quicktype_utils_1.emitMultiline)(this, linesString, 2);
27
+ }
28
+ emitSourceStructure() {
29
+ if (this.leadingComments !== undefined) {
30
+ this.emitCommentLines(this.leadingComments);
31
+ }
32
+ else {
33
+ this.emitUsageComments();
34
+ }
35
+ }
36
+ emitPredefinedJSDocTypes() {
37
+ this.emitMultiline(`
38
+ /**
39
+ * Typedef for a DeviceTimestamp
40
+ * @typedef {object} DeviceTimestamp
41
+ * @property {string} type The value of 'dtm'
42
+ * @property {number} value The value of the device timestamp
43
+ */
44
+
45
+ /**
46
+ * Typedef for a TrueTimestamp
47
+ * @typedef {object} TrueTimestamp
48
+ * @property {string} type The value of 'ttm'
49
+ * @property {number} value The value of the true timestamp
50
+ */
51
+
52
+ /**
53
+ * Typedef for a Timestamp
54
+ * @typedef {object} Timestamp
55
+ * @property {number|TrueTimestamp|DeviceTimestamp} [timestamp] The value of the timestamp
56
+ */
57
+
58
+ /**
59
+ * Typedef for a SelfDescribingJson
60
+ * @typedef {object} SelfDescribingJson
61
+ * @property {string} schema The schema of the context
62
+ * @property {object} data The data to send for the context
63
+ */
64
+
65
+ /**
66
+ * Typedef for a Context
67
+ * @typedef {object} Context
68
+ * @property {SelfDescribingJson[]} [context] Contexts to include in the event
69
+ */
70
+ `);
71
+ this.ensureBlankLine();
72
+ }
73
+ emitSource(givenOutputFilename) {
74
+ super.emitSource(givenOutputFilename);
75
+ this.ensureBlankLine();
76
+ this.emitPredefinedJSDocTypes();
77
+ this.forEachTopLevel("none", (_, name) => {
78
+ const title = this.sourcelikeToString(name);
79
+ const { raw } = _.getAttributes().get(metadata_1.eventMetadataAttributeKind);
80
+ raw.title = raw.title || title;
81
+ this.emitMultiline((0, json_schema_to_jsdoc_1.generate)(raw));
82
+ });
83
+ (0, quicktype_utils_1.executeRenderPlan)(this, this.snowtypeOptions.generators);
84
+ }
85
+ makeNameForTopLevel(t, givenName, maybeNamedType) {
86
+ return (0, quicktype_utils_1.makeNameForTopLevelWithPrefixAndSuffix)((...args) => {
87
+ return super.makeNameForTopLevel(...args);
88
+ }, this.snowtypeOptions, t, givenName, maybeNamedType);
89
+ }
90
+ }
91
+ // We extend one of the target languages in quicktype to add our own functions
92
+ // This is only necesary to make it use our own renderer
93
+ class SnowtypeJSLanguage extends quicktype_core_1.JavaScriptTargetLanguage {
94
+ constructor(snowtypeOptions) {
95
+ super();
96
+ this.snowtypeOptions = snowtypeOptions;
97
+ }
98
+ makeRenderer(renderContext, untypedOptionValues) {
99
+ return new SnowtypeJavaScriptRenderer(this, renderContext, (0, quicktype_core_1.getOptionValues)(quicktype_core_1.tsFlowOptions, untypedOptionValues), this.snowtypeOptions);
100
+ }
101
+ }
102
+ const jsBase = (0, quicktype_1.createQuicktypeLanguageGenerator)({
103
+ name: "javascript",
104
+ quicktypeLanguage: SnowtypeJSLanguage,
105
+ defaultOptions: {
106
+ "runtime-typecheck": false,
107
+ },
108
+ nameModifiers: {
109
+ functionName: Strings_1.camelCase,
110
+ },
111
+ });
112
+ exports.javascript = Object.assign(Object.assign({}, jsBase), { generate: (schemaRepositories, dataProducts, options) => __awaiter(void 0, void 0, void 0, function* () {
113
+ // @ts-expect-error
114
+ const { sdk, prefixes, suffixes } = options;
115
+ const result = yield jsBase.generate(schemaRepositories, dataProducts, options);
116
+ return result;
117
+ }) });
@@ -0,0 +1 @@
1
+ export declare const kotlin: import("./types").LanguageGenerator;