@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.16
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/lib/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +755 -147
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +146 -146
- package/lib/category.js.map +1 -1
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +11 -0
- package/lib/chunks.js.map +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +161 -0
- package/lib/config.js.map +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +130 -0
- package/lib/crypto.js.map +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +8 -0
- package/lib/debug.js.map +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +7 -6
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +117 -114
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +150 -119
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.types.js +4 -3
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -14
- package/lib/index.js.map +1 -1
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +28 -28
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +95 -90
- package/lib/pagination.js.map +1 -1
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +40 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +351 -178
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +238 -130
- package/lib/protocol-rest.js.map +1 -1
- package/lib/query.js +16 -16
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +284 -0
- package/lib/response-validation-strict.js.map +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +112 -70
- package/lib/response-validation.js.map +1 -1
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +49 -49
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +142 -154
- package/lib/retry.js.map +1 -1
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +341 -0
- package/lib/schema-lite-impl.js.map +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +27 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +31 -0
- package/lib/schema-lite.js.map +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +202 -30
- package/lib/schema.js.map +1 -1
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +22 -21
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +80 -80
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +38 -26
- package/lib/xml.js.map +1 -1
- package/package.json +9 -7
- package/src/api.ts +1079 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/src/category.ts
CHANGED
|
@@ -148,22 +148,22 @@ export const withRetryable =
|
|
|
148
148
|
// Category Decorators (convenience functions for common categories)
|
|
149
149
|
// ============================================================================
|
|
150
150
|
|
|
151
|
-
export const withAuthError = withCategory(AuthError);
|
|
152
|
-
export const withBadRequestError = withCategory(BadRequestError);
|
|
153
|
-
export const withConflictError = withCategory(ConflictError);
|
|
154
|
-
export const withNotFoundError = withCategory(NotFoundError);
|
|
155
|
-
export const withQuotaError = withCategory(QuotaError);
|
|
156
|
-
export const withServerError = withCategory(ServerError);
|
|
157
|
-
export const withThrottlingError = withCategory(ThrottlingError);
|
|
158
|
-
export const withNetworkError = withCategory(NetworkError);
|
|
159
|
-
export const withParseError = withCategory(ParseError);
|
|
160
|
-
export const withConfigurationError = withCategory(ConfigurationError);
|
|
161
|
-
export const withTimeoutError = withCategory(TimeoutError);
|
|
162
|
-
export const withRetryableError = withCategory(RetryableError);
|
|
163
|
-
export const withLockedError = withCategory(LockedError);
|
|
164
|
-
export const withAbortedError = withCategory(AbortedError);
|
|
165
|
-
export const withAlreadyExistsError = withCategory(AlreadyExistsError);
|
|
166
|
-
export const withDependencyViolationError = withCategory(DependencyViolationError);
|
|
151
|
+
export const withAuthError = /*@__PURE__*/ withCategory(AuthError);
|
|
152
|
+
export const withBadRequestError = /*@__PURE__*/ withCategory(BadRequestError);
|
|
153
|
+
export const withConflictError = /*@__PURE__*/ withCategory(ConflictError);
|
|
154
|
+
export const withNotFoundError = /*@__PURE__*/ withCategory(NotFoundError);
|
|
155
|
+
export const withQuotaError = /*@__PURE__*/ withCategory(QuotaError);
|
|
156
|
+
export const withServerError = /*@__PURE__*/ withCategory(ServerError);
|
|
157
|
+
export const withThrottlingError = /*@__PURE__*/ withCategory(ThrottlingError);
|
|
158
|
+
export const withNetworkError = /*@__PURE__*/ withCategory(NetworkError);
|
|
159
|
+
export const withParseError = /*@__PURE__*/ withCategory(ParseError);
|
|
160
|
+
export const withConfigurationError = /*@__PURE__*/ withCategory(ConfigurationError);
|
|
161
|
+
export const withTimeoutError = /*@__PURE__*/ withCategory(TimeoutError);
|
|
162
|
+
export const withRetryableError = /*@__PURE__*/ withCategory(RetryableError);
|
|
163
|
+
export const withLockedError = /*@__PURE__*/ withCategory(LockedError);
|
|
164
|
+
export const withAbortedError = /*@__PURE__*/ withCategory(AbortedError);
|
|
165
|
+
export const withAlreadyExistsError = /*@__PURE__*/ withCategory(AlreadyExistsError);
|
|
166
|
+
export const withDependencyViolationError = /*@__PURE__*/ withCategory(DependencyViolationError);
|
|
167
167
|
|
|
168
168
|
// ============================================================================
|
|
169
169
|
// Category Predicates
|
|
@@ -244,7 +244,7 @@ export const isThrottling = (error: unknown): boolean => {
|
|
|
244
244
|
/**
|
|
245
245
|
* Check if an error is an Effect `HttpClientError` caused by a wire-level
|
|
246
246
|
* transport failure (undici `ConnectTimeoutError`, socket reset, DNS
|
|
247
|
-
* failure, premature stream close,
|
|
247
|
+
* failure, premature stream close, ...). The request never reached the
|
|
248
248
|
* server (or the response never finished) so retrying is safe.
|
|
249
249
|
*
|
|
250
250
|
* Status-code retries are intentionally left to the per-SDK API client,
|
|
@@ -337,22 +337,22 @@ export const catchErrors =
|
|
|
337
337
|
// Alias for convenience
|
|
338
338
|
export { catchErrors as catch };
|
|
339
339
|
|
|
340
|
-
export const catchAuthError = makeCatcher(AuthError);
|
|
341
|
-
export const catchBadRequestError = makeCatcher(BadRequestError);
|
|
342
|
-
export const catchConflictError = makeCatcher(ConflictError);
|
|
343
|
-
export const catchNotFoundError = makeCatcher(NotFoundError);
|
|
344
|
-
export const catchQuotaError = makeCatcher(QuotaError);
|
|
345
|
-
export const catchServerError = makeCatcher(ServerError);
|
|
346
|
-
export const catchThrottlingError = makeCatcher(ThrottlingError);
|
|
347
|
-
export const catchNetworkError = makeCatcher(NetworkError);
|
|
348
|
-
export const catchParseError = makeCatcher(ParseError);
|
|
349
|
-
export const catchConfigurationError = makeCatcher(ConfigurationError);
|
|
350
|
-
export const catchTimeoutError = makeCatcher(TimeoutError);
|
|
351
|
-
export const catchRetryableError = makeCatcher(RetryableError);
|
|
352
|
-
export const catchLockedError = makeCatcher(LockedError);
|
|
353
|
-
export const catchAbortedError = makeCatcher(AbortedError);
|
|
354
|
-
export const catchAlreadyExistsError = makeCatcher(AlreadyExistsError);
|
|
355
|
-
export const catchDependencyViolationError = makeCatcher(DependencyViolationError);
|
|
340
|
+
export const catchAuthError = /*@__PURE__*/ makeCatcher(AuthError);
|
|
341
|
+
export const catchBadRequestError = /*@__PURE__*/ makeCatcher(BadRequestError);
|
|
342
|
+
export const catchConflictError = /*@__PURE__*/ makeCatcher(ConflictError);
|
|
343
|
+
export const catchNotFoundError = /*@__PURE__*/ makeCatcher(NotFoundError);
|
|
344
|
+
export const catchQuotaError = /*@__PURE__*/ makeCatcher(QuotaError);
|
|
345
|
+
export const catchServerError = /*@__PURE__*/ makeCatcher(ServerError);
|
|
346
|
+
export const catchThrottlingError = /*@__PURE__*/ makeCatcher(ThrottlingError);
|
|
347
|
+
export const catchNetworkError = /*@__PURE__*/ makeCatcher(NetworkError);
|
|
348
|
+
export const catchParseError = /*@__PURE__*/ makeCatcher(ParseError);
|
|
349
|
+
export const catchConfigurationError = /*@__PURE__*/ makeCatcher(ConfigurationError);
|
|
350
|
+
export const catchTimeoutError = /*@__PURE__*/ makeCatcher(TimeoutError);
|
|
351
|
+
export const catchRetryableError = /*@__PURE__*/ makeCatcher(RetryableError);
|
|
352
|
+
export const catchLockedError = /*@__PURE__*/ makeCatcher(LockedError);
|
|
353
|
+
export const catchAbortedError = /*@__PURE__*/ makeCatcher(AbortedError);
|
|
354
|
+
export const catchAlreadyExistsError = /*@__PURE__*/ makeCatcher(AlreadyExistsError);
|
|
355
|
+
export const catchDependencyViolationError = /*@__PURE__*/ makeCatcher(DependencyViolationError);
|
|
356
356
|
|
|
357
357
|
/**
|
|
358
358
|
* Catch errors with specified categories with full type narrowing.
|
package/src/chunks.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated schema consts built from chunked builder functions.
|
|
3
|
+
*
|
|
4
|
+
* A generated service module declares thousands of schema consts. Evaluating
|
|
5
|
+
* each initializer at import allocated a thunk closure, its compiled-function
|
|
6
|
+
* record, a lazy wrapper and an annotation object -- about 330 bytes a
|
|
7
|
+
* schema. The generator now moves the initializers into builder functions
|
|
8
|
+
* of a few schemas each (`switch (j) { case 0: return S.Struct(...) }`), and
|
|
9
|
+
* every const is a small lazy schema holding its builder and index:
|
|
10
|
+
*
|
|
11
|
+
* const Customer = /*@__PURE__*\/ __L.at(__c12, 3) as any as S.Schema<Customer>;
|
|
12
|
+
* function __c12(j: number) { switch (j) { case 3: return S.suspend(...) } }
|
|
13
|
+
*
|
|
14
|
+
* The initializer runs on first use, exactly as written, so the schema is
|
|
15
|
+
* the same. V8 compiles a builder only when one of its schemas is first
|
|
16
|
+
* used, and the code text lives only in the module source.
|
|
17
|
+
*/
|
|
18
|
+
import type * as S from "effect/Schema";
|
|
19
|
+
import { lazyFrom, type LazyBuilder } from "./schema.ts";
|
|
20
|
+
|
|
21
|
+
const builders = /*@__PURE__*/ new WeakMap<(j: number) => unknown, LazyBuilder>();
|
|
22
|
+
|
|
23
|
+
/** Schema `j` of the chunk `build`, built on first use. */
|
|
24
|
+
// `any`: each const keeps the type it declares or casts to.
|
|
25
|
+
export const at = (build: (j: number) => unknown, j: number): any => {
|
|
26
|
+
let builder = builders.get(build);
|
|
27
|
+
if (!builder)
|
|
28
|
+
builders.set(build, (builder = { build: (data) => build(data as number) as S.Top }));
|
|
29
|
+
return lazyFrom(builder, j);
|
|
30
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move module-private schema initializers into chunked builder functions
|
|
3
|
+
* (dev-time only; runtime helper: `@distilled.cloud/core/chunks`).
|
|
4
|
+
*
|
|
5
|
+
* const Customer = S.suspend(() => ...).annotate({ identifier: "Customer" }) as any as S.Schema<Customer>;
|
|
6
|
+
* becomes
|
|
7
|
+
* const Customer = /*@__PURE__*\/ __L.at(__c12, 3) as any as S.Schema<Customer>;
|
|
8
|
+
* ...
|
|
9
|
+
* function __c12(j: number): any { switch (j) { ... case 3: return S.suspend(() => ...).annotate({ identifier: "Customer" }); } }
|
|
10
|
+
*
|
|
11
|
+
* Builders are function declarations at the end of the module (hoisted, so
|
|
12
|
+
* the consts can name them at import); their bodies run only on first use,
|
|
13
|
+
* after the module has finished evaluating.
|
|
14
|
+
*/
|
|
15
|
+
import { parseAst } from "rolldown/parseAst";
|
|
16
|
+
import { valueRefs } from "./privatize.ts";
|
|
17
|
+
|
|
18
|
+
type Node = { readonly type: string; readonly start: number; readonly end: number } & Record<
|
|
19
|
+
string,
|
|
20
|
+
unknown
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
/** Schemas per builder function: smaller chunks compile less on first use. */
|
|
24
|
+
export const CHUNK_SIZE = 32;
|
|
25
|
+
|
|
26
|
+
const stripCasts = (n: Node): Node => {
|
|
27
|
+
while (
|
|
28
|
+
n.type === "TSAsExpression" ||
|
|
29
|
+
n.type === "TSSatisfiesExpression" ||
|
|
30
|
+
n.type === "ParenthesizedExpression"
|
|
31
|
+
)
|
|
32
|
+
n = n.expression as Node;
|
|
33
|
+
return n;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const chunkSchemas = (
|
|
37
|
+
code: string,
|
|
38
|
+
filename = "generated.ts",
|
|
39
|
+
chunkSize = CHUNK_SIZE,
|
|
40
|
+
): { code: string; chunked: number } => {
|
|
41
|
+
const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
|
|
42
|
+
const body = program.body as unknown as Node[];
|
|
43
|
+
const items: Array<{ start: number; end: number; text: string; name: string; key: string }> = [];
|
|
44
|
+
for (const st of body) {
|
|
45
|
+
// Only module-private consts: exports keep their own initializer.
|
|
46
|
+
if (st.type !== "VariableDeclaration" || (st.declarations as Node[]).length !== 1) continue;
|
|
47
|
+
const d = (st.declarations as Node[])[0]!;
|
|
48
|
+
if (!d.init) continue;
|
|
49
|
+
const inner = stripCasts(d.init as Node);
|
|
50
|
+
if (inner.type !== "CallExpression") continue;
|
|
51
|
+
const text = code.slice(inner.start, inner.end);
|
|
52
|
+
if (/\bAPI\.make/.test(text) || !/\bS\./.test(text)) continue;
|
|
53
|
+
items.push({
|
|
54
|
+
start: inner.start,
|
|
55
|
+
end: inner.end,
|
|
56
|
+
text,
|
|
57
|
+
name: ((d.id as Node).name as string) ?? "",
|
|
58
|
+
key: "",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!items.length) return { code, chunked: 0 };
|
|
62
|
+
|
|
63
|
+
// Group schemas only with schemas reached by exactly the same roots
|
|
64
|
+
// (operations and error classes): a bundle that keeps one builder then
|
|
65
|
+
// needs every schema in it, so nothing unused comes along.
|
|
66
|
+
const refsOf = new Map<string, Set<string>>();
|
|
67
|
+
const roots: Array<Set<string>> = [];
|
|
68
|
+
for (const st of body) {
|
|
69
|
+
const decl =
|
|
70
|
+
st.type === "ExportNamedDeclaration" && st.declaration ? (st.declaration as Node) : st;
|
|
71
|
+
if (decl.type === "VariableDeclaration") {
|
|
72
|
+
for (const d of decl.declarations as Node[]) {
|
|
73
|
+
const name = (d.id as Node).name as string | undefined;
|
|
74
|
+
if (!name || !d.init) continue;
|
|
75
|
+
const refs = valueRefs(d.init, new Set());
|
|
76
|
+
refsOf.set(name, refs);
|
|
77
|
+
const init = d.init as Node;
|
|
78
|
+
if (/\bAPI\.make/.test(code.slice(init.start, init.end))) roots.push(refs);
|
|
79
|
+
}
|
|
80
|
+
} else if (decl.type === "ClassDeclaration" && decl.id) {
|
|
81
|
+
const refs = valueRefs(decl.superClass, new Set());
|
|
82
|
+
refsOf.set((decl.id as Node).name as string, refs);
|
|
83
|
+
roots.push(refs);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const reachedBy = new Map<string, number[]>();
|
|
87
|
+
roots.forEach((rootRefs, r) => {
|
|
88
|
+
const seen = new Set<string>();
|
|
89
|
+
const stack = [...rootRefs];
|
|
90
|
+
while (stack.length) {
|
|
91
|
+
const n = stack.pop()!;
|
|
92
|
+
if (seen.has(n) || !refsOf.has(n)) continue;
|
|
93
|
+
seen.add(n);
|
|
94
|
+
let list = reachedBy.get(n);
|
|
95
|
+
if (!list) reachedBy.set(n, (list = []));
|
|
96
|
+
list.push(r);
|
|
97
|
+
for (const x of refsOf.get(n)!) stack.push(x);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
for (const it of items) it.key = (reachedBy.get(it.name) ?? []).join(",");
|
|
101
|
+
const ordered = items
|
|
102
|
+
.map((it, i) => [it, i] as const)
|
|
103
|
+
.sort((a, b) => (a[0].key < b[0].key ? -1 : a[0].key > b[0].key ? 1 : a[1] - b[1]));
|
|
104
|
+
const slot = new Map<(typeof items)[number], [number, number]>();
|
|
105
|
+
let chunk = -1;
|
|
106
|
+
let used = chunkSize;
|
|
107
|
+
let lastKey: string | undefined;
|
|
108
|
+
for (const [it] of ordered) {
|
|
109
|
+
if (used >= chunkSize || it.key !== lastKey) {
|
|
110
|
+
chunk++;
|
|
111
|
+
used = 0;
|
|
112
|
+
lastKey = it.key;
|
|
113
|
+
}
|
|
114
|
+
slot.set(it, [chunk, used++]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const cases: string[][] = [];
|
|
118
|
+
for (const it of items) {
|
|
119
|
+
const [c, j] = slot.get(it)!;
|
|
120
|
+
(cases[c] ??= [])[j] = `case ${j}: return ${it.text};`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let out = code;
|
|
124
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
125
|
+
const it = items[i]!;
|
|
126
|
+
// The PURE marker in front of the old initializer, if any, now marks the `at` call.
|
|
127
|
+
const marked = /\/\*[@#]__PURE__\*\/\s*$/.test(out.slice(Math.max(0, it.start - 20), it.start));
|
|
128
|
+
const [c, j] = slot.get(it)!;
|
|
129
|
+
out = `${out.slice(0, it.start)}${marked ? "" : "/*@__PURE__*/ "}__L.at(__c${c}, ${j})${out.slice(it.end)}`;
|
|
130
|
+
}
|
|
131
|
+
const lastImport = [...body].reverse().find((s) => s.type === "ImportDeclaration");
|
|
132
|
+
const at = lastImport ? lastImport.end : 0;
|
|
133
|
+
// Modules on lite schemas take `at` from schema-lite (lazy lite nodes).
|
|
134
|
+
const helper = code.includes('"@distilled.cloud/core/schema-lite"')
|
|
135
|
+
? "@distilled.cloud/core/schema-lite"
|
|
136
|
+
: "@distilled.cloud/core/chunks";
|
|
137
|
+
out = `${out.slice(0, at)}\nimport * as __L from "${helper}";${out.slice(at)}`;
|
|
138
|
+
out +=
|
|
139
|
+
"\n// Schema builders: each runs one schema initializer, on that schema's first use.\n" +
|
|
140
|
+
cases
|
|
141
|
+
.map(
|
|
142
|
+
(c, k) =>
|
|
143
|
+
`function __c${k}(j: number): any {\n switch (j) {\n${c.map((x) => ` ${x}`).join("\n")}\n }\n}`,
|
|
144
|
+
)
|
|
145
|
+
.join("\n");
|
|
146
|
+
return { code: out, chunked: items.length };
|
|
147
|
+
};
|
package/src/codegen/cli.ts
CHANGED
|
@@ -16,10 +16,16 @@ import { Flag } from "effect/cli";
|
|
|
16
16
|
import { Command } from "effect/cli";
|
|
17
17
|
import * as FileSystem from "effect/FileSystem";
|
|
18
18
|
import * as Path from "effect/Path";
|
|
19
|
+
import { chunkSchemas } from "./chunk.ts";
|
|
20
|
+
import { dedupeSchemas } from "./dedupe.ts";
|
|
19
21
|
import { barrel } from "./emit.ts";
|
|
20
22
|
import { formatGenerated } from "./format.ts";
|
|
21
23
|
import { stampGeneratedAt } from "./generated-at.ts";
|
|
22
24
|
import { generateService, type SdkSpec } from "./generator.ts";
|
|
25
|
+
import { toLatin1 } from "./latin1.ts";
|
|
26
|
+
import { privatizeSchemas, typeOnlyNamespaceImports } from "./privatize.ts";
|
|
27
|
+
import { annotateNestedCalls } from "./pure.ts";
|
|
28
|
+
import { tableSchemas } from "./table.ts";
|
|
23
29
|
|
|
24
30
|
export interface GeneratorCliOptions {
|
|
25
31
|
/** Command description shown in --help. */
|
|
@@ -184,8 +190,28 @@ export const runGeneratorCli = (options: GeneratorCliOptions): void => {
|
|
|
184
190
|
yield* Console.error(`❌ ${resource}`);
|
|
185
191
|
continue;
|
|
186
192
|
}
|
|
187
|
-
const {
|
|
193
|
+
const { operations } = generated;
|
|
188
194
|
if (operations === 0) continue;
|
|
195
|
+
// Every nested call in a top-level initializer gets a PURE marker,
|
|
196
|
+
// so one unused schema cannot pin others in a consumer's bundle.
|
|
197
|
+
// Latin-1-only source halves the heap V8 keeps for the module text.
|
|
198
|
+
// Structurally identical schemas become aliases of one schema, and
|
|
199
|
+
// schema consts become module-private (types stay exported).
|
|
200
|
+
const resourceFile = `${resource}.ts`;
|
|
201
|
+
const marked = annotateNestedCalls(generated.code, resourceFile);
|
|
202
|
+
const code = toLatin1(
|
|
203
|
+
typeOnlyNamespaceImports(
|
|
204
|
+
tableSchemas(
|
|
205
|
+
chunkSchemas(
|
|
206
|
+
privatizeSchemas(dedupeSchemas(marked, resourceFile).code, resourceFile).code,
|
|
207
|
+
resourceFile,
|
|
208
|
+
).code,
|
|
209
|
+
resourceFile,
|
|
210
|
+
).code,
|
|
211
|
+
resourceFile,
|
|
212
|
+
),
|
|
213
|
+
resourceFile,
|
|
214
|
+
);
|
|
189
215
|
|
|
190
216
|
yield* fs.writeFileString(path.join(outDir, `${resource}.ts`), code);
|
|
191
217
|
written.push(resource);
|