@suss/ir-core 0.1.1 → 0.2.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.
@@ -129,6 +129,9 @@ var BoundaryBindingSchema = z.object({
129
129
  semantics: SemanticsSchema,
130
130
  recognition: z.string()
131
131
  });
132
+ function typeDefinitionKey(ref) {
133
+ return ref.def ?? null;
134
+ }
132
135
  var TypeShapeSchema = z.lazy(
133
136
  () => z.discriminatedUnion("type", [
134
137
  z.object({
@@ -156,11 +159,52 @@ var TypeShapeSchema = z.lazy(
156
159
  z.object({
157
160
  type: z.literal("ref"),
158
161
  name: z.string(),
159
- from: z.string().optional()
162
+ from: z.string().optional(),
163
+ def: z.string().optional()
160
164
  }),
161
165
  z.object({ type: z.literal("unknown") })
162
166
  ])
163
167
  );
168
+ var MAX_DEFINITION_DEPTH = 6;
169
+ function withDefinitionsInlined(shape, definitions, depth = 0, inProgress = /* @__PURE__ */ new Set()) {
170
+ if (definitions === void 0 || depth >= MAX_DEFINITION_DEPTH) {
171
+ return shape;
172
+ }
173
+ const deeper = (inner) => withDefinitionsInlined(inner, definitions, depth + 1, inProgress);
174
+ if (shape.type === "ref") {
175
+ const key = typeDefinitionKey(shape);
176
+ if (key === null) {
177
+ return shape;
178
+ }
179
+ const defined = definitions[key];
180
+ if (defined === void 0 || inProgress.has(key)) {
181
+ return shape;
182
+ }
183
+ return withDefinitionsInlined(
184
+ defined,
185
+ definitions,
186
+ depth,
187
+ /* @__PURE__ */ new Set([...inProgress, key])
188
+ );
189
+ }
190
+ if (shape.type === "record") {
191
+ const properties = {};
192
+ for (const [name, value] of Object.entries(shape.properties)) {
193
+ properties[name] = deeper(value);
194
+ }
195
+ return { ...shape, properties };
196
+ }
197
+ if (shape.type === "array") {
198
+ return { ...shape, items: deeper(shape.items) };
199
+ }
200
+ if (shape.type === "dictionary") {
201
+ return { ...shape, values: deeper(shape.values) };
202
+ }
203
+ if (shape.type === "union") {
204
+ return { ...shape, variants: shape.variants.map(deeper) };
205
+ }
206
+ return shape;
207
+ }
164
208
 
165
209
  export {
166
210
  ConfidenceSourceSchema,
@@ -178,5 +222,7 @@ export {
178
222
  MessageBusSemanticsSchema,
179
223
  SemanticsSchema,
180
224
  BoundaryBindingSchema,
181
- TypeShapeSchema
225
+ typeDefinitionKey,
226
+ TypeShapeSchema,
227
+ withDefinitionsInlined
182
228
  };
package/dist/index.cjs CHANGED
@@ -59,7 +59,9 @@ __export(index_exports, {
59
59
  ruleBoundaryMatchesKey: () => ruleBoundaryMatchesKey,
60
60
  runtimeConfigBinding: () => runtimeConfigBinding,
61
61
  storageRelationalBinding: () => storageRelationalBinding,
62
- validateRule: () => validateRule
62
+ typeDefinitionKey: () => typeDefinitionKey,
63
+ validateRule: () => validateRule,
64
+ withDefinitionsInlined: () => withDefinitionsInlined
63
65
  });
64
66
  module.exports = __toCommonJS(index_exports);
65
67
 
@@ -194,6 +196,9 @@ var BoundaryBindingSchema = import_zod.z.object({
194
196
  semantics: SemanticsSchema,
195
197
  recognition: import_zod.z.string()
196
198
  });
199
+ function typeDefinitionKey(ref) {
200
+ return ref.def ?? null;
201
+ }
197
202
  var TypeShapeSchema = import_zod.z.lazy(
198
203
  () => import_zod.z.discriminatedUnion("type", [
199
204
  import_zod.z.object({
@@ -221,11 +226,52 @@ var TypeShapeSchema = import_zod.z.lazy(
221
226
  import_zod.z.object({
222
227
  type: import_zod.z.literal("ref"),
223
228
  name: import_zod.z.string(),
224
- from: import_zod.z.string().optional()
229
+ from: import_zod.z.string().optional(),
230
+ def: import_zod.z.string().optional()
225
231
  }),
226
232
  import_zod.z.object({ type: import_zod.z.literal("unknown") })
227
233
  ])
228
234
  );
235
+ var MAX_DEFINITION_DEPTH = 6;
236
+ function withDefinitionsInlined(shape, definitions, depth = 0, inProgress = /* @__PURE__ */ new Set()) {
237
+ if (definitions === void 0 || depth >= MAX_DEFINITION_DEPTH) {
238
+ return shape;
239
+ }
240
+ const deeper = (inner) => withDefinitionsInlined(inner, definitions, depth + 1, inProgress);
241
+ if (shape.type === "ref") {
242
+ const key = typeDefinitionKey(shape);
243
+ if (key === null) {
244
+ return shape;
245
+ }
246
+ const defined = definitions[key];
247
+ if (defined === void 0 || inProgress.has(key)) {
248
+ return shape;
249
+ }
250
+ return withDefinitionsInlined(
251
+ defined,
252
+ definitions,
253
+ depth,
254
+ /* @__PURE__ */ new Set([...inProgress, key])
255
+ );
256
+ }
257
+ if (shape.type === "record") {
258
+ const properties = {};
259
+ for (const [name, value] of Object.entries(shape.properties)) {
260
+ properties[name] = deeper(value);
261
+ }
262
+ return { ...shape, properties };
263
+ }
264
+ if (shape.type === "array") {
265
+ return { ...shape, items: deeper(shape.items) };
266
+ }
267
+ if (shape.type === "dictionary") {
268
+ return { ...shape, values: deeper(shape.values) };
269
+ }
270
+ if (shape.type === "union") {
271
+ return { ...shape, variants: shape.variants.map(deeper) };
272
+ }
273
+ return shape;
274
+ }
229
275
 
230
276
  // src/channel.ts
231
277
  function parseChannel(channel) {
@@ -709,5 +755,7 @@ function messageBusBinding(opts) {
709
755
  ruleBoundaryMatchesKey,
710
756
  runtimeConfigBinding,
711
757
  storageRelationalBinding,
712
- validateRule
758
+ typeDefinitionKey,
759
+ validateRule,
760
+ withDefinitionsInlined
713
761
  });
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { TypeShape, BoundaryBindingSchema, ConfidenceInfoSchema, ConfidenceLevelSchema, ConfidenceSourceSchema, CorroborationSchema, DeployableUnitSchema, SemanticsSchema, SourceLocationSchema } from './schemas.cjs';
3
- export { FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, StorageRelationalSemanticsSchema, TypeShapeSchema } from './schemas.cjs';
3
+ export { FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, StorageRelationalSemanticsSchema, TypeShapeSchema, typeDefinitionKey, withDefinitionsInlined } from './schemas.cjs';
4
4
 
5
5
  /**
6
6
  * Normalize a route path to a canonical form for matching.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { TypeShape, BoundaryBindingSchema, ConfidenceInfoSchema, ConfidenceLevelSchema, ConfidenceSourceSchema, CorroborationSchema, DeployableUnitSchema, SemanticsSchema, SourceLocationSchema } from './schemas.js';
3
- export { FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, StorageRelationalSemanticsSchema, TypeShapeSchema } from './schemas.js';
3
+ export { FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, StorageRelationalSemanticsSchema, TypeShapeSchema, typeDefinitionKey, withDefinitionsInlined } from './schemas.js';
4
4
 
5
5
  /**
6
6
  * Normalize a route path to a canonical form for matching.
package/dist/index.js CHANGED
@@ -14,8 +14,10 @@ import {
14
14
  SemanticsSchema,
15
15
  SourceLocationSchema,
16
16
  StorageRelationalSemanticsSchema,
17
- TypeShapeSchema
18
- } from "./chunk-QQLJDL3C.js";
17
+ TypeShapeSchema,
18
+ typeDefinitionKey,
19
+ withDefinitionsInlined
20
+ } from "./chunk-JIFTLUZX.js";
19
21
 
20
22
  // src/channel.ts
21
23
  function parseChannel(channel) {
@@ -498,5 +500,7 @@ export {
498
500
  ruleBoundaryMatchesKey,
499
501
  runtimeConfigBinding,
500
502
  storageRelationalBinding,
501
- validateRule
503
+ typeDefinitionKey,
504
+ validateRule,
505
+ withDefinitionsInlined
502
506
  };
package/dist/schemas.cjs CHANGED
@@ -35,7 +35,9 @@ __export(schemas_exports, {
35
35
  SemanticsSchema: () => SemanticsSchema,
36
36
  SourceLocationSchema: () => SourceLocationSchema,
37
37
  StorageRelationalSemanticsSchema: () => StorageRelationalSemanticsSchema,
38
- TypeShapeSchema: () => TypeShapeSchema
38
+ TypeShapeSchema: () => TypeShapeSchema,
39
+ typeDefinitionKey: () => typeDefinitionKey,
40
+ withDefinitionsInlined: () => withDefinitionsInlined
39
41
  });
40
42
  module.exports = __toCommonJS(schemas_exports);
41
43
  var import_zod = require("zod");
@@ -168,6 +170,9 @@ var BoundaryBindingSchema = import_zod.z.object({
168
170
  semantics: SemanticsSchema,
169
171
  recognition: import_zod.z.string()
170
172
  });
173
+ function typeDefinitionKey(ref) {
174
+ return ref.def ?? null;
175
+ }
171
176
  var TypeShapeSchema = import_zod.z.lazy(
172
177
  () => import_zod.z.discriminatedUnion("type", [
173
178
  import_zod.z.object({
@@ -195,11 +200,52 @@ var TypeShapeSchema = import_zod.z.lazy(
195
200
  import_zod.z.object({
196
201
  type: import_zod.z.literal("ref"),
197
202
  name: import_zod.z.string(),
198
- from: import_zod.z.string().optional()
203
+ from: import_zod.z.string().optional(),
204
+ def: import_zod.z.string().optional()
199
205
  }),
200
206
  import_zod.z.object({ type: import_zod.z.literal("unknown") })
201
207
  ])
202
208
  );
209
+ var MAX_DEFINITION_DEPTH = 6;
210
+ function withDefinitionsInlined(shape, definitions, depth = 0, inProgress = /* @__PURE__ */ new Set()) {
211
+ if (definitions === void 0 || depth >= MAX_DEFINITION_DEPTH) {
212
+ return shape;
213
+ }
214
+ const deeper = (inner) => withDefinitionsInlined(inner, definitions, depth + 1, inProgress);
215
+ if (shape.type === "ref") {
216
+ const key = typeDefinitionKey(shape);
217
+ if (key === null) {
218
+ return shape;
219
+ }
220
+ const defined = definitions[key];
221
+ if (defined === void 0 || inProgress.has(key)) {
222
+ return shape;
223
+ }
224
+ return withDefinitionsInlined(
225
+ defined,
226
+ definitions,
227
+ depth,
228
+ /* @__PURE__ */ new Set([...inProgress, key])
229
+ );
230
+ }
231
+ if (shape.type === "record") {
232
+ const properties = {};
233
+ for (const [name, value] of Object.entries(shape.properties)) {
234
+ properties[name] = deeper(value);
235
+ }
236
+ return { ...shape, properties };
237
+ }
238
+ if (shape.type === "array") {
239
+ return { ...shape, items: deeper(shape.items) };
240
+ }
241
+ if (shape.type === "dictionary") {
242
+ return { ...shape, values: deeper(shape.values) };
243
+ }
244
+ if (shape.type === "union") {
245
+ return { ...shape, variants: shape.variants.map(deeper) };
246
+ }
247
+ return shape;
248
+ }
203
249
  // Annotate the CommonJS export names for ESM import in node:
204
250
  0 && (module.exports = {
205
251
  BoundaryBindingSchema,
@@ -217,5 +263,7 @@ var TypeShapeSchema = import_zod.z.lazy(
217
263
  SemanticsSchema,
218
264
  SourceLocationSchema,
219
265
  StorageRelationalSemanticsSchema,
220
- TypeShapeSchema
266
+ TypeShapeSchema,
267
+ typeDefinitionKey,
268
+ withDefinitionsInlined
221
269
  });
@@ -317,6 +317,17 @@ type TypeShape = {
317
317
  } | {
318
318
  type: "ref";
319
319
  name: string;
320
+ /**
321
+ * Where this type is written down, when it is. The key into the
322
+ * summary's table of definitions.
323
+ *
324
+ * A name does not identify a type. Every instantiation of one
325
+ * generic reports the generic's own name and file, so `Omit<User,
326
+ * "secret">` and `Omit<Order, "total">` are both `Omit`, and a
327
+ * table keyed on that hands the second one the first one's
328
+ * fields. This is built from what the type actually is.
329
+ */
330
+ def?: string | undefined;
320
331
  /**
321
332
  * The file that declares this type, when the project declares it.
322
333
  * Absent for a name the language or a dependency owns, which means
@@ -330,6 +341,33 @@ type TypeShape = {
330
341
  } | {
331
342
  type: "unknown";
332
343
  };
344
+ /**
345
+ * How a table of definitions names the type a ref points at.
346
+ *
347
+ * A ref carries the name and the file that declares it, and that pair
348
+ * already identifies the type, so a table keyed on it needs nothing new
349
+ * on the ref. A name the language or a dependency owns has no file and
350
+ * keys on the name alone.
351
+ */
352
+ declare function typeDefinitionKey(ref: {
353
+ def?: string | undefined;
354
+ }): string | null;
333
355
  declare const TypeShapeSchema: z.ZodType<TypeShape>;
356
+ /**
357
+ * A shape with the definitions it names put back into it.
358
+ *
359
+ * Comparing two shapes means comparing their structure, and a ref has
360
+ * none. Rather than teach every comparison to look in a table, the
361
+ * table goes back into the shape once, and everything downstream reads
362
+ * what it always read.
363
+ *
364
+ * Putting a definition back is a substitution rather than a level of
365
+ * nesting, so it does not spend depth. Counting it did: a type six
366
+ * deep came back three deep, and a consumer reading a field past that
367
+ * point was told the provider did not have it. What stops a type that
368
+ * names itself is the set of names already being put back on this
369
+ * path, which is how the shape walk guards its own cycles.
370
+ */
371
+ declare function withDefinitionsInlined(shape: TypeShape, definitions: Record<string, TypeShape> | undefined, depth?: number, inProgress?: ReadonlySet<string>): TypeShape;
334
372
 
335
- export { BoundaryBindingSchema, ConfidenceInfoSchema, ConfidenceLevelSchema, ConfidenceSourceSchema, CorroborationSchema, DeployableUnitSchema, FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, SemanticsSchema, SourceLocationSchema, StorageRelationalSemanticsSchema, type TypeShape, TypeShapeSchema };
373
+ export { BoundaryBindingSchema, ConfidenceInfoSchema, ConfidenceLevelSchema, ConfidenceSourceSchema, CorroborationSchema, DeployableUnitSchema, FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, SemanticsSchema, SourceLocationSchema, StorageRelationalSemanticsSchema, type TypeShape, TypeShapeSchema, typeDefinitionKey, withDefinitionsInlined };
package/dist/schemas.d.ts CHANGED
@@ -317,6 +317,17 @@ type TypeShape = {
317
317
  } | {
318
318
  type: "ref";
319
319
  name: string;
320
+ /**
321
+ * Where this type is written down, when it is. The key into the
322
+ * summary's table of definitions.
323
+ *
324
+ * A name does not identify a type. Every instantiation of one
325
+ * generic reports the generic's own name and file, so `Omit<User,
326
+ * "secret">` and `Omit<Order, "total">` are both `Omit`, and a
327
+ * table keyed on that hands the second one the first one's
328
+ * fields. This is built from what the type actually is.
329
+ */
330
+ def?: string | undefined;
320
331
  /**
321
332
  * The file that declares this type, when the project declares it.
322
333
  * Absent for a name the language or a dependency owns, which means
@@ -330,6 +341,33 @@ type TypeShape = {
330
341
  } | {
331
342
  type: "unknown";
332
343
  };
344
+ /**
345
+ * How a table of definitions names the type a ref points at.
346
+ *
347
+ * A ref carries the name and the file that declares it, and that pair
348
+ * already identifies the type, so a table keyed on it needs nothing new
349
+ * on the ref. A name the language or a dependency owns has no file and
350
+ * keys on the name alone.
351
+ */
352
+ declare function typeDefinitionKey(ref: {
353
+ def?: string | undefined;
354
+ }): string | null;
333
355
  declare const TypeShapeSchema: z.ZodType<TypeShape>;
356
+ /**
357
+ * A shape with the definitions it names put back into it.
358
+ *
359
+ * Comparing two shapes means comparing their structure, and a ref has
360
+ * none. Rather than teach every comparison to look in a table, the
361
+ * table goes back into the shape once, and everything downstream reads
362
+ * what it always read.
363
+ *
364
+ * Putting a definition back is a substitution rather than a level of
365
+ * nesting, so it does not spend depth. Counting it did: a type six
366
+ * deep came back three deep, and a consumer reading a field past that
367
+ * point was told the provider did not have it. What stops a type that
368
+ * names itself is the set of names already being put back on this
369
+ * path, which is how the shape walk guards its own cycles.
370
+ */
371
+ declare function withDefinitionsInlined(shape: TypeShape, definitions: Record<string, TypeShape> | undefined, depth?: number, inProgress?: ReadonlySet<string>): TypeShape;
334
372
 
335
- export { BoundaryBindingSchema, ConfidenceInfoSchema, ConfidenceLevelSchema, ConfidenceSourceSchema, CorroborationSchema, DeployableUnitSchema, FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, SemanticsSchema, SourceLocationSchema, StorageRelationalSemanticsSchema, type TypeShape, TypeShapeSchema };
373
+ export { BoundaryBindingSchema, ConfidenceInfoSchema, ConfidenceLevelSchema, ConfidenceSourceSchema, CorroborationSchema, DeployableUnitSchema, FunctionCallSemanticsSchema, GraphqlOperationSemanticsSchema, GraphqlResolverSemanticsSchema, MessageBusSemanticsSchema, RestSemanticsSchema, RuntimeConfigSemanticsSchema, SemanticsSchema, SourceLocationSchema, StorageRelationalSemanticsSchema, type TypeShape, TypeShapeSchema, typeDefinitionKey, withDefinitionsInlined };
package/dist/schemas.js CHANGED
@@ -14,8 +14,10 @@ import {
14
14
  SemanticsSchema,
15
15
  SourceLocationSchema,
16
16
  StorageRelationalSemanticsSchema,
17
- TypeShapeSchema
18
- } from "./chunk-QQLJDL3C.js";
17
+ TypeShapeSchema,
18
+ typeDefinitionKey,
19
+ withDefinitionsInlined
20
+ } from "./chunk-JIFTLUZX.js";
19
21
  export {
20
22
  BoundaryBindingSchema,
21
23
  ConfidenceInfoSchema,
@@ -32,5 +34,7 @@ export {
32
34
  SemanticsSchema,
33
35
  SourceLocationSchema,
34
36
  StorageRelationalSemanticsSchema,
35
- TypeShapeSchema
37
+ TypeShapeSchema,
38
+ typeDefinitionKey,
39
+ withDefinitionsInlined
36
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/ir-core",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Shared IR primitives for suss — type shapes, boundary bindings, source locations, and confidence. Imported by both @suss/behavioral-ir and @suss/intent-ir so neither depends on the other.",
6
6
  "keywords": [