@skmtc/core 0.58.2 → 0.58.4

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 (63) hide show
  1. package/esm/context/BuiltOnRead.d.ts +37 -0
  2. package/esm/context/BuiltOnRead.js +199 -0
  3. package/esm/context/CoreContext.js +11 -5
  4. package/esm/context/GenerateContext.d.ts +3 -3
  5. package/esm/context/GenerateContext.js +13 -6
  6. package/esm/context/ParseContext.js +116 -11
  7. package/esm/context/Subject.d.ts +29 -2
  8. package/esm/context/Subject.js +67 -6
  9. package/esm/context/generateTypes.d.ts +2 -2
  10. package/esm/dsl/model/ModelDriver.js +2 -2
  11. package/esm/dsl/operation/gql/GqlOperationDriver.js +2 -2
  12. package/esm/dsl/operation/oas/OasOperationDriver.js +2 -2
  13. package/esm/dsl/webhook/WebhookDriver.js +2 -2
  14. package/esm/helpers/getPath.d.ts +6 -0
  15. package/esm/helpers/getPath.js +6 -0
  16. package/esm/helpers/isDeepEqual.d.ts +17 -0
  17. package/esm/helpers/isDeepEqual.js +93 -0
  18. package/esm/helpers/parseModuleName.d.ts +8 -8
  19. package/esm/helpers/parseModuleName.js +8 -8
  20. package/esm/helpers/toVariantList.d.ts +1 -1
  21. package/esm/oas/document/Document.d.ts +5 -1
  22. package/esm/oas/document/Document.js +10 -1
  23. package/esm/oas/document/documentSource.d.ts +37 -0
  24. package/esm/oas/document/documentSource.js +27 -0
  25. package/esm/oas/schema/siblings.js +6 -4
  26. package/esm/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  27. package/esm/parse/v3-0/operation/toOperationsV3.js +68 -67
  28. package/esm/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  29. package/esm/parse/v3-1/operation/toOperationsV3.js +68 -67
  30. package/esm/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  31. package/esm/parse/v3-2/operation/toOperationsV3.js +69 -68
  32. package/package.json +1 -4
  33. package/script/context/BuiltOnRead.d.ts +37 -0
  34. package/script/context/BuiltOnRead.js +203 -0
  35. package/script/context/CoreContext.js +11 -5
  36. package/script/context/GenerateContext.d.ts +3 -3
  37. package/script/context/GenerateContext.js +13 -6
  38. package/script/context/ParseContext.js +116 -11
  39. package/script/context/Subject.d.ts +29 -2
  40. package/script/context/Subject.js +67 -6
  41. package/script/context/generateTypes.d.ts +2 -2
  42. package/script/dsl/model/ModelDriver.js +2 -5
  43. package/script/dsl/operation/gql/GqlOperationDriver.js +2 -5
  44. package/script/dsl/operation/oas/OasOperationDriver.js +2 -2
  45. package/script/dsl/webhook/WebhookDriver.js +2 -5
  46. package/script/helpers/getPath.d.ts +6 -0
  47. package/script/helpers/getPath.js +10 -0
  48. package/script/helpers/isDeepEqual.d.ts +17 -0
  49. package/script/helpers/isDeepEqual.js +97 -0
  50. package/script/helpers/parseModuleName.d.ts +8 -8
  51. package/script/helpers/parseModuleName.js +8 -8
  52. package/script/helpers/toVariantList.d.ts +1 -1
  53. package/script/oas/document/Document.d.ts +5 -1
  54. package/script/oas/document/Document.js +10 -1
  55. package/script/oas/document/documentSource.d.ts +37 -0
  56. package/script/oas/document/documentSource.js +36 -0
  57. package/script/oas/schema/siblings.js +6 -7
  58. package/script/parse/v3-0/operation/toOperationsV3.d.ts +14 -0
  59. package/script/parse/v3-0/operation/toOperationsV3.js +71 -69
  60. package/script/parse/v3-1/operation/toOperationsV3.d.ts +14 -0
  61. package/script/parse/v3-1/operation/toOperationsV3.js +71 -69
  62. package/script/parse/v3-2/operation/toOperationsV3.d.ts +14 -0
  63. package/script/parse/v3-2/operation/toOperationsV3.js +72 -70
@@ -1,5 +1,24 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _OasOperationSubject_operation, _OasOperationSubject_loader, _OasOperationSubject_inStep;
1
13
  import { toModelKey } from '../helpers/refFns.js';
2
- /** An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`. */
14
+ /**
15
+ * An OpenAPI operation as a subject. Its results and enrichments are at `[path][method]`.
16
+ *
17
+ * It holds the operation it is constructed with. In a run that builds
18
+ * operations on read, it lets that one go once the file plan is built. In
19
+ * its step, the first read builds its operation through the document, and
20
+ * it lets the operation go when the step has run.
21
+ */
3
22
  export class OasOperationSubject {
4
23
  constructor(operation) {
5
24
  Object.defineProperty(this, "type", {
@@ -8,7 +27,13 @@ export class OasOperationSubject {
8
27
  writable: true,
9
28
  value: 'oasOperation'
10
29
  });
11
- Object.defineProperty(this, "operation", {
30
+ Object.defineProperty(this, "path", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "method", {
12
37
  enumerable: true,
13
38
  configurable: true,
14
39
  writable: true,
@@ -32,18 +57,53 @@ export class OasOperationSubject {
32
57
  writable: true,
33
58
  value: void 0
34
59
  });
35
- this.operation = operation;
60
+ _OasOperationSubject_operation.set(this, void 0);
61
+ _OasOperationSubject_loader.set(this, void 0);
62
+ /** Whether its step runs now. */
63
+ _OasOperationSubject_inStep.set(this, false);
64
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, operation, "f");
65
+ this.path = operation.path;
66
+ this.method = operation.method;
36
67
  this.trail = [operation.path, operation.method];
37
68
  this.enrichmentPath = this.trail;
38
69
  this.label = `${operation.method.toUpperCase()} ${operation.path}`;
39
70
  }
71
+ /**
72
+ * Its operation. In a run that builds operations on read, only while its
73
+ * step runs: the first read in the step builds it.
74
+ */
75
+ get operation() {
76
+ if (__classPrivateFieldGet(this, _OasOperationSubject_operation, "f") === undefined && __classPrivateFieldGet(this, _OasOperationSubject_inStep, "f") && __classPrivateFieldGet(this, _OasOperationSubject_loader, "f") !== undefined) {
77
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, __classPrivateFieldGet(this, _OasOperationSubject_loader, "f").load(this), "f");
78
+ }
79
+ if (__classPrivateFieldGet(this, _OasOperationSubject_operation, "f") === undefined) {
80
+ throw new Error(`The operation of ${this.label} is read outside its step, after it was let go`);
81
+ }
82
+ return __classPrivateFieldGet(this, _OasOperationSubject_operation, "f");
83
+ }
84
+ /** Lets go of the operation it was constructed with: from now on, `loader` gives it. */
85
+ buildOnRead(loader) {
86
+ __classPrivateFieldSet(this, _OasOperationSubject_loader, loader, "f");
87
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, undefined, "f");
88
+ }
89
+ /** Its step starts. A step that never reads its operation, such as one with no generator, builds none. */
90
+ startStep() {
91
+ __classPrivateFieldSet(this, _OasOperationSubject_inStep, true, "f");
92
+ }
93
+ /** Its step has run: it lets go of the operation the step built. */
94
+ finishStep() {
95
+ __classPrivateFieldSet(this, _OasOperationSubject_inStep, false, "f");
96
+ if (__classPrivateFieldGet(this, _OasOperationSubject_loader, "f") !== undefined) {
97
+ __classPrivateFieldGet(this, _OasOperationSubject_loader, "f").letGo(this);
98
+ __classPrivateFieldSet(this, _OasOperationSubject_operation, undefined, "f");
99
+ }
100
+ }
40
101
  isSupported({ entry, context, variant }) {
41
102
  return (typeof entry.isSupported !== 'function' ||
42
103
  entry.isSupported({ operation: this.operation, context, variant }));
43
104
  }
44
105
  matches(filter, variant) {
45
- const { path, method } = this.operation;
46
- return matchesPathFilter({ paths: filter, path, method, variant });
106
+ return matchesPathFilter({ paths: filter, path: this.path, method: this.method, variant });
47
107
  }
48
108
  transform({ entry, context, variant }) {
49
109
  entry.transform({ context, operation: this.operation, variant });
@@ -59,12 +119,13 @@ export class OasOperationSubject {
59
119
  return projection.toExportPath({ operation: this.operation, enrichments, variant });
60
120
  }
61
121
  toNamedModels(reach) {
62
- return reach.namedByOperation(this.operation);
122
+ return reach.namedByOperation(this);
63
123
  }
64
124
  toSource({ generatorId, variant }) {
65
125
  return toOasOperationSource({ operation: this.operation, generatorId, variant });
66
126
  }
67
127
  }
128
+ _OasOperationSubject_operation = new WeakMap(), _OasOperationSubject_loader = new WeakMap(), _OasOperationSubject_inStep = new WeakMap();
68
129
  /**
69
130
  * A 3.1 webhook as a subject. Its results are at `['webhook'][name][method]`
70
131
  * and its enrichments at `[name][method]`. A filter has the shape of an
@@ -497,8 +497,8 @@ export type GenerateContextType = {
497
497
  * The recording enrichment accessor — the single choke point every
498
498
  * enrichment lookup routes through. Reads the node at
499
499
  * `settings.enrichments[...segments]` (segments are literal keys, never
500
- * dotted lodash paths) and records the read for the post-walk
501
- * consumption audit, so configured-but-never-read entries surface as
500
+ * dotted paths) and records the read for the post-walk consumption
501
+ * audit, so configured-but-never-read entries surface as
502
502
  * `UNCONSUMED_ENRICHMENT` warnings.
503
503
  */
504
504
  readEnrichment: (segments: readonly string[]) => unknown;
@@ -3,7 +3,7 @@ import { toModelGeneratorKey } from '../GeneratorKeys.js';
3
3
  import { toModelKey } from '../../helpers/refFns.js';
4
4
  import { DEFAULT_VARIANT } from '../../types/Variant.js';
5
5
  import { readProjectionOptions, toValueOptions } from '../../types/ProjectionOptions.js';
6
- import isEqual from 'lodash-es/isEqual.js';
6
+ import { isDeepEqual } from '../../helpers/isDeepEqual.js';
7
7
  import { CodeFileBase } from '../CodeFileBase.js';
8
8
  import { PendingDefinition } from '../PendingDefinition.js';
9
9
  /**
@@ -211,7 +211,7 @@ const assertSameKey = ({ name, exportPath, cachedKey, generatorKey }) => {
211
211
  };
212
212
  /** One name in one file built with other caller options collides too: options are identity. */
213
213
  const assertSameOptions = ({ name, exportPath, cachedOptions, options }) => {
214
- if (!isEqual(cachedOptions, options)) {
214
+ if (!isDeepEqual(cachedOptions, options)) {
215
215
  throw new Error(`Registered definition mismatch: '${name}' in file '${exportPath}'. Cached options ${JSON.stringify(cachedOptions)} do not match new options ${JSON.stringify(options)}. Fold options into toIdentifierName.`);
216
216
  }
217
217
  };
@@ -2,7 +2,7 @@ import { ensureFile, findDefinitionAt, toImportDestination, toImportFile } from
2
2
  import { toGqlOperationGeneratorKey } from '../../GeneratorKeys.js';
3
3
  import { DEFAULT_VARIANT } from '../../../types/Variant.js';
4
4
  import { readProjectionOptions, toValueOptions } from '../../../types/ProjectionOptions.js';
5
- import isEqual from 'lodash-es/isEqual.js';
5
+ import { isDeepEqual } from '../../../helpers/isDeepEqual.js';
6
6
  /**
7
7
  * Driver for the GraphQL operation insertion lifecycle.
8
8
  *
@@ -169,7 +169,7 @@ export class GqlOperationDriver {
169
169
  // Options are identity, like the variant, but cannot ride the key: a hit
170
170
  // is checked against the options its value was built with.
171
171
  const cachedOptions = toValueOptions(definition.value);
172
- if (!isEqual(cachedOptions, this.options)) {
172
+ if (!isDeepEqual(cachedOptions, this.options)) {
173
173
  throw new Error(`Registered definition mismatch: '${definition.identifier.name}' in file '${exportPath}'. Cached options ${JSON.stringify(cachedOptions)} do not match new options ${JSON.stringify(this.options)}. Fold options into toIdentifierName.`);
174
174
  }
175
175
  return true;
@@ -15,7 +15,7 @@ import invariant from 'tiny-invariant';
15
15
  import { toOasOperationGeneratorKey } from '../../GeneratorKeys.js';
16
16
  import { DEFAULT_VARIANT } from '../../../types/Variant.js';
17
17
  import { readProjectionOptions, toValueOptions } from '../../../types/ProjectionOptions.js';
18
- import isEqual from 'lodash-es/isEqual.js';
18
+ import { isDeepEqual } from '../../../helpers/isDeepEqual.js';
19
19
  /**
20
20
  * Driver for the OAS operation insertion lifecycle.
21
21
  *
@@ -232,7 +232,7 @@ export class OasOperationDriver {
232
232
  // Options are identity, like the variant, but cannot ride the key: a hit
233
233
  // is checked against the options its value was built with.
234
234
  const cachedOptions = toValueOptions(definition.value);
235
- if (!isEqual(cachedOptions, this.options)) {
235
+ if (!isDeepEqual(cachedOptions, this.options)) {
236
236
  throw new Error(`Registered definition mismatch: '${definition.identifier.name}' in file '${exportPath}'. Cached options ${JSON.stringify(cachedOptions)} do not match new options ${JSON.stringify(this.options)}. Fold options into toIdentifierName.`);
237
237
  }
238
238
  return true;
@@ -2,7 +2,7 @@ import { ensureFile, findDefinitionAt, toImportDestination, toImportFile } from
2
2
  import { toWebhookGeneratorKey } from '../GeneratorKeys.js';
3
3
  import { DEFAULT_VARIANT } from '../../types/Variant.js';
4
4
  import { readProjectionOptions, toValueOptions } from '../../types/ProjectionOptions.js';
5
- import isEqual from 'lodash-es/isEqual.js';
5
+ import { isDeepEqual } from '../../helpers/isDeepEqual.js';
6
6
  /**
7
7
  * Driver for the webhook insertion lifecycle.
8
8
  *
@@ -162,7 +162,7 @@ export class WebhookDriver {
162
162
  // Options are identity, like the variant, but cannot ride the key: a hit
163
163
  // is checked against the options its value was built with.
164
164
  const cachedOptions = toValueOptions(definition.value);
165
- if (!isEqual(cachedOptions, this.options)) {
165
+ if (!isDeepEqual(cachedOptions, this.options)) {
166
166
  throw new Error(`Registered definition mismatch: '${definition.identifier.name}' in file '${exportPath}'. Cached options ${JSON.stringify(cachedOptions)} do not match new options ${JSON.stringify(this.options)}. Fold options into toIdentifierName.`);
167
167
  }
168
168
  return true;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The value at `path` in `value`. Each step is one literal key, so a key with
3
+ * dots or brackets (an operation path) stays whole. A step from `undefined` or
4
+ * `null` gives `undefined`.
5
+ */
6
+ export declare const getPath: (value: unknown, path: readonly [string, ...string[]]) => unknown;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The value at `path` in `value`. Each step is one literal key, so a key with
3
+ * dots or brackets (an operation path) stays whole. A step from `undefined` or
4
+ * `null` gives `undefined`.
5
+ */
6
+ export const getPath = (value, path) => path.reduce((current, key) => current === undefined || current === null ? undefined : Reflect.get(Object(current), key), value);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Whether two values have the same content.
3
+ *
4
+ * - Primitives and functions are equal to themselves; `NaN` equals `NaN`, and
5
+ * `0` equals `-0`.
6
+ * - Arrays are equal item by item; a hole is `undefined`.
7
+ * - Objects need one constructor and the same own enumerable keys, in any
8
+ * order: `{ a: undefined }` is not `{}`. Private fields are not read.
9
+ * - Dates and boxed booleans, numbers and strings are equal by value, regular
10
+ * expressions by source and flags, errors by name and message, typed arrays
11
+ * by their items, and maps and sets by their entries in any order.
12
+ * - Cycles of the same shape are equal.
13
+ * - Every other kind of object (an `ArrayBuffer`, a `DataView`, a boxed symbol
14
+ * or bigint, a promise) is equal to itself only. A boxed primitive is not
15
+ * equal to the primitive.
16
+ */
17
+ export declare const isDeepEqual: (left: unknown, right: unknown) => boolean;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Whether two values have the same content.
3
+ *
4
+ * - Primitives and functions are equal to themselves; `NaN` equals `NaN`, and
5
+ * `0` equals `-0`.
6
+ * - Arrays are equal item by item; a hole is `undefined`.
7
+ * - Objects need one constructor and the same own enumerable keys, in any
8
+ * order: `{ a: undefined }` is not `{}`. Private fields are not read.
9
+ * - Dates and boxed booleans, numbers and strings are equal by value, regular
10
+ * expressions by source and flags, errors by name and message, typed arrays
11
+ * by their items, and maps and sets by their entries in any order.
12
+ * - Cycles of the same shape are equal.
13
+ * - Every other kind of object (an `ArrayBuffer`, a `DataView`, a boxed symbol
14
+ * or bigint, a promise) is equal to itself only. A boxed primitive is not
15
+ * equal to the primitive.
16
+ */
17
+ export const isDeepEqual = (left, right) => isEqualWithin(left, right, new Map());
18
+ const isEqualWithin = (left, right, pairs) => {
19
+ if (left === right || (Number.isNaN(left) && Number.isNaN(right))) {
20
+ return true;
21
+ }
22
+ if (!isObject(left) || !isObject(right)) {
23
+ return false;
24
+ }
25
+ const tag = toTag(left);
26
+ if (tag !== toTag(right)) {
27
+ return false;
28
+ }
29
+ const partner = pairs.get(left);
30
+ if (partner !== undefined && pairs.has(right)) {
31
+ return partner === right && pairs.get(right) === left;
32
+ }
33
+ pairs.set(left, right).set(right, left);
34
+ const result = isSameContent({ left, right, tag, pairs });
35
+ pairs.delete(left);
36
+ pairs.delete(right);
37
+ return result;
38
+ };
39
+ const isObject = (value) => typeof value === 'object' && value !== null;
40
+ const toTag = (value) => Object.prototype.toString.call(value);
41
+ const isSameContent = ({ left, right, tag, pairs }) => {
42
+ switch (tag) {
43
+ case '[object Object]':
44
+ return isSameObject(left, right, pairs);
45
+ case '[object Array]':
46
+ return Array.isArray(left) && Array.isArray(right) && isSameItems(left, right, pairs);
47
+ case '[object Map]':
48
+ return (left instanceof Map && right instanceof Map && isSameUnordered([...left], [...right], pairs));
49
+ case '[object Set]':
50
+ return (left instanceof Set && right instanceof Set && isSameUnordered([...left], [...right], pairs));
51
+ case '[object Boolean]':
52
+ case '[object Number]':
53
+ case '[object Date]':
54
+ return isEqualWithin(Number(left), Number(right), pairs);
55
+ case '[object String]':
56
+ case '[object RegExp]':
57
+ return String(left) === String(right);
58
+ case '[object Error]':
59
+ return left instanceof Error && right instanceof Error && isSameError(left, right);
60
+ default:
61
+ // The indices of a typed array are its own enumerable keys.
62
+ return isTypedArray(left) && isSameObject(left, right, pairs);
63
+ }
64
+ };
65
+ const isSameError = (left, right) => left.name === right.name && left.message === right.message;
66
+ const isTypedArray = (value) => ArrayBuffer.isView(value) && !(value instanceof DataView);
67
+ const isSameObject = (left, right, pairs) => {
68
+ const keys = toEnumerableKeys(left);
69
+ return (keys.length === toEnumerableKeys(right).length &&
70
+ keys.every(key => Object.hasOwn(right, key) &&
71
+ isEqualWithin(Reflect.get(left, key), Reflect.get(right, key), pairs)) &&
72
+ // An own `constructor` key is data, such as a property of that name: it
73
+ // was compared with the other keys.
74
+ (keys.includes('constructor') || isSameConstructor(left, right)));
75
+ };
76
+ const toEnumerableKeys = (value) => Reflect.ownKeys(value).filter(key => Object.prototype.propertyIsEnumerable.call(value, key));
77
+ /** An object with no prototype has no constructor, and matches an object literal. */
78
+ const isSameConstructor = (left, right) => left.constructor === right.constructor || !('constructor' in left && 'constructor' in right);
79
+ const isSameItems = (left, right, pairs) => left.length === right.length &&
80
+ // `Array.from` reads a hole as `undefined`, where `every` would skip it.
81
+ Array.from(left).every((item, index) => isEqualWithin(item, right[index], pairs));
82
+ const isSameUnordered = (left, right, pairs) => {
83
+ const unmatched = [...right];
84
+ return (left.length === right.length &&
85
+ left.every(item => {
86
+ const index = unmatched.findIndex(other => isEqualWithin(item, other, pairs));
87
+ if (index === -1) {
88
+ return false;
89
+ }
90
+ unmatched.splice(index, 1);
91
+ return true;
92
+ }));
93
+ };
@@ -47,21 +47,21 @@ export type ParsedModuleName = {
47
47
  * import { parseModuleName } from '@skmtc/core';
48
48
  *
49
49
  * // Simple package name
50
- * const simple = parseModuleName('lodash');
50
+ * const simple = parseModuleName('zod');
51
51
  * // {
52
52
  * // scheme: null,
53
53
  * // scopeName: null,
54
- * // packageName: 'lodash',
54
+ * // packageName: 'zod',
55
55
  * // version: null
56
56
  * // }
57
57
  *
58
58
  * // Package with version
59
- * const versioned = parseModuleName('lodash@4.17.21');
59
+ * const versioned = parseModuleName('zod@3.23.8');
60
60
  * // {
61
61
  * // scheme: null,
62
62
  * // scopeName: null,
63
- * // packageName: 'lodash',
64
- * // version: '4.17.21'
63
+ * // packageName: 'zod',
64
+ * // version: '3.23.8'
65
65
  * // }
66
66
  * ```
67
67
  *
@@ -98,12 +98,12 @@ export type ParsedModuleName = {
98
98
  * // }
99
99
  *
100
100
  * // npm module with scheme
101
- * const npmModule = parseModuleName('npm:lodash@^4.17.0');
101
+ * const npmModule = parseModuleName('npm:zod@^3.23.0');
102
102
  * // {
103
103
  * // scheme: 'npm',
104
104
  * // scopeName: null,
105
- * // packageName: 'lodash',
106
- * // version: '^4.17.0'
105
+ * // packageName: 'zod',
106
+ * // version: '^3.23.0'
107
107
  * // }
108
108
  *
109
109
  * // HTTPS module
@@ -19,21 +19,21 @@
19
19
  * import { parseModuleName } from '@skmtc/core';
20
20
  *
21
21
  * // Simple package name
22
- * const simple = parseModuleName('lodash');
22
+ * const simple = parseModuleName('zod');
23
23
  * // {
24
24
  * // scheme: null,
25
25
  * // scopeName: null,
26
- * // packageName: 'lodash',
26
+ * // packageName: 'zod',
27
27
  * // version: null
28
28
  * // }
29
29
  *
30
30
  * // Package with version
31
- * const versioned = parseModuleName('lodash@4.17.21');
31
+ * const versioned = parseModuleName('zod@3.23.8');
32
32
  * // {
33
33
  * // scheme: null,
34
34
  * // scopeName: null,
35
- * // packageName: 'lodash',
36
- * // version: '4.17.21'
35
+ * // packageName: 'zod',
36
+ * // version: '3.23.8'
37
37
  * // }
38
38
  * ```
39
39
  *
@@ -70,12 +70,12 @@
70
70
  * // }
71
71
  *
72
72
  * // npm module with scheme
73
- * const npmModule = parseModuleName('npm:lodash@^4.17.0');
73
+ * const npmModule = parseModuleName('npm:zod@^3.23.0');
74
74
  * // {
75
75
  * // scheme: 'npm',
76
76
  * // scopeName: null,
77
- * // packageName: 'lodash',
78
- * // version: '^4.17.0'
77
+ * // packageName: 'zod',
78
+ * // version: '^3.23.0'
79
79
  * // }
80
80
  *
81
81
  * // HTTPS module
@@ -2,7 +2,7 @@ type ToVariantListArgs = {
2
2
  /**
3
3
  * The enrichment block at `[generatorId][path][method]` (OAS) or
4
4
  * `[generatorId][rootKind][fieldName]` (GQL). Typed as `unknown`
5
- * because `lodash-es/get()` returns `unknown` and the engine
5
+ * because `readEnrichment` returns `unknown` and the engine
6
6
  * doesn't pre-validate this branch.
7
7
  */
8
8
  opEnrichments: unknown;
@@ -231,7 +231,11 @@ export declare class OasDocument {
231
231
  /** API metadata */
232
232
  get info(): OasInfo;
233
233
  get servers(): OasServer[] | undefined;
234
- /** List of all operations for the API */
234
+ /**
235
+ * List of all operations for the API. In a run with `onArtifact` the parsed
236
+ * operations are let go once the file plan is built; the first time they
237
+ * are listed after that, each is built again and kept.
238
+ */
235
239
  get operations(): OasOperation[];
236
240
  /** List of all 3.1 webhooks for the API (kept separate from operations) */
237
241
  get webhooks(): OasWebhook[];
@@ -11,6 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _OasDocument_fields, _OasDocument_refTargets;
13
13
  import "../../_dnt.polyfills.js";
14
+ import { takeUnlistedOperations } from './documentSource.js';
14
15
  /**
15
16
  * Represents a complete OpenAPI v3 document in the SKMTC OAS processing system.
16
17
  *
@@ -289,11 +290,19 @@ export class OasDocument {
289
290
  }
290
291
  return __classPrivateFieldGet(this, _OasDocument_fields, "f").servers;
291
292
  }
292
- /** List of all operations for the API */
293
+ /**
294
+ * List of all operations for the API. In a run with `onArtifact` the parsed
295
+ * operations are let go once the file plan is built; the first time they
296
+ * are listed after that, each is built again and kept.
297
+ */
293
298
  get operations() {
294
299
  if (!__classPrivateFieldGet(this, _OasDocument_fields, "f")) {
295
300
  throw new Error(`Accessing 'operations' before fields are set`);
296
301
  }
302
+ const list = takeUnlistedOperations(this);
303
+ if (list !== undefined) {
304
+ __classPrivateFieldGet(this, _OasDocument_fields, "f").operations = list();
305
+ }
297
306
  return __classPrivateFieldGet(this, _OasDocument_fields, "f").operations;
298
307
  }
299
308
  /** List of all 3.1 webhooks for the API (kept separate from operations) */
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A document whose operations and component schemas are built again when a
3
+ * generator reads them, in a run with `onArtifact`. Internal: `mod.ts` does
4
+ * not list this file.
5
+ */
6
+ import type { OasDocument } from './Document.js';
7
+ import type { OasOperation } from '../operation/Operation.js';
8
+ import type { OasSchema } from '../schema/Schema.js';
9
+ import type { OasRef } from '../ref/Ref.js';
10
+ import type { Method } from '../../types/Method.js';
11
+ import type { RefName } from '../../types/RefName.js';
12
+ /** Where an operation is in a document. An `OasOperation` fits it. */
13
+ export type OperationPlace = {
14
+ path: string;
15
+ method: Method;
16
+ };
17
+ /**
18
+ * How the parse context that parsed a document builds one of its operations
19
+ * or component schemas again from the input document. A rebuild records no
20
+ * issue and no ref.
21
+ */
22
+ export type DocumentSource = {
23
+ toOperation(place: OperationPlace): OasOperation;
24
+ toSchema(name: RefName): OasSchema | OasRef<'schema'>;
25
+ };
26
+ /** Marks a parse context, before it parses, as one of a run that gives files early. */
27
+ export declare const markPlannedParse: (parseContext: object) => void;
28
+ /** Whether `markPlannedParse` marked the parse context. */
29
+ export declare const isPlannedParse: (parseContext: object) => boolean;
30
+ /** Keeps how the parse context builds the parts of `document` again. */
31
+ export declare const setDocumentSource: (document: OasDocument, source: DocumentSource) => void;
32
+ /** How the parts of `document` are built again, or `undefined` when its run builds nothing again. */
33
+ export declare const toDocumentSource: (document: OasDocument) => DocumentSource | undefined;
34
+ /** `document` has let its parsed operations go: `list` builds every one, the first time they are listed. */
35
+ export declare const setUnlistedOperations: (document: OasDocument, list: () => OasOperation[]) => void;
36
+ /** How to list the operations of `document` that were let go, once: after that they are listed. */
37
+ export declare const takeUnlistedOperations: (document: OasDocument) => (() => OasOperation[]) | undefined;
@@ -0,0 +1,27 @@
1
+ const sources = new WeakMap();
2
+ /** The parse contexts of runs that give files early, whose documents are built on read. */
3
+ const plannedParses = new WeakSet();
4
+ /** Marks a parse context, before it parses, as one of a run that gives files early. */
5
+ export const markPlannedParse = (parseContext) => {
6
+ plannedParses.add(parseContext);
7
+ };
8
+ /** Whether `markPlannedParse` marked the parse context. */
9
+ export const isPlannedParse = (parseContext) => plannedParses.has(parseContext);
10
+ /** Each document whose parsed operations were let go, and how to list them all again. */
11
+ const unlistedOperations = new WeakMap();
12
+ /** Keeps how the parse context builds the parts of `document` again. */
13
+ export const setDocumentSource = (document, source) => {
14
+ sources.set(document, source);
15
+ };
16
+ /** How the parts of `document` are built again, or `undefined` when its run builds nothing again. */
17
+ export const toDocumentSource = (document) => sources.get(document);
18
+ /** `document` has let its parsed operations go: `list` builds every one, the first time they are listed. */
19
+ export const setUnlistedOperations = (document, list) => {
20
+ unlistedOperations.set(document, list);
21
+ };
22
+ /** How to list the operations of `document` that were let go, once: after that they are listed. */
23
+ export const takeUnlistedOperations = (document) => {
24
+ const list = unlistedOperations.get(document);
25
+ unlistedOperations.delete(document);
26
+ return list;
27
+ };
@@ -1,5 +1,5 @@
1
1
  import * as v from 'valibot';
2
- import isEqual from 'lodash-es/isEqual.js';
2
+ import { isDeepEqual } from '../../helpers/isDeepEqual.js';
3
3
  import { DanglingRefError } from '../ref/DanglingRefError.js';
4
4
  import { numberFormat } from '../number/number-types.js';
5
5
  import { integerFormat } from '../integer/integer-types.js';
@@ -140,7 +140,9 @@ const toChangedKeywords = (copy, target, siblings) => {
140
140
  }
141
141
  const applied = Reflect.get(copy, keyword);
142
142
  const original = Reflect.get(target, keyword);
143
- return BOOLEAN_KEYWORDS.includes(keyword) ? (applied === true) !== (original === true) : !isEqual(applied, original);
143
+ return BOOLEAN_KEYWORDS.includes(keyword)
144
+ ? (applied === true) !== (original === true)
145
+ : !isDeepEqual(applied, original);
144
146
  });
145
147
  };
146
148
  /** Whether the keywords next to a reference change `target` at that site. The engine behind `OasRef.resolve`. */
@@ -194,13 +196,13 @@ export const toSkippedSiblings = (target, siblings, nullable) => {
194
196
  */
195
197
  export const toChangedObjectKeywords = (target, siblings) => {
196
198
  const objects = target.toTargetParts().filter(part => part.type === 'object');
197
- const isSame = (keyword) => objects.some(object => isEqual(object[keyword], siblings[keyword]));
199
+ const isSame = (keyword) => objects.some(object => isDeepEqual(object[keyword], siblings[keyword]));
198
200
  const isUnchanged = (keyword) => {
199
201
  switch (keyword) {
200
202
  case 'required':
201
203
  return (siblings.required ?? []).every(name => objects.some(object => object.required?.includes(name)));
202
204
  case 'properties':
203
- return Object.keys(siblings.properties ?? {}).every(name => objects.some(object => isEqual(object.properties?.[name], siblings.properties?.[name])));
205
+ return Object.keys(siblings.properties ?? {}).every(name => objects.some(object => isDeepEqual(object.properties?.[name], siblings.properties?.[name])));
204
206
  case 'additionalProperties':
205
207
  case 'minProperties':
206
208
  case 'maxProperties':
@@ -22,4 +22,18 @@ export type ToOperationsV3Args = {
22
22
  context: ParseContextType;
23
23
  };
24
24
  export declare const toOperationsV3: ({ paths, stackTrail, context }: ToOperationsV3Args) => OasOperation[];
25
+ export type ToPathOperationsV3Args = {
26
+ path: string;
27
+ pathItem: OpenAPIV3.PathItemObject;
28
+ /** The trail of the path item, with `path` already pushed. */
29
+ stackTrail: StackTrail;
30
+ context: ParseContextType;
31
+ /** Parses only the operation at this method. */
32
+ method?: Method;
33
+ };
34
+ /**
35
+ * The operations of the path item at `path`. They share one parsed path
36
+ * item. With `method`, only the operation at that method is parsed.
37
+ */
38
+ export declare const toPathOperationsV3: ({ path, pathItem, stackTrail: pathStack, context, method: only }: ToPathOperationsV3Args) => OasOperation[];
25
39
  export {};