@secondlayer/shared 10.0.1 → 11.0.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.
- package/dist/src/db/index.js.map +1 -1
- package/dist/src/db/queries/chain-reorgs.js.map +1 -1
- package/dist/src/db/queries/subgraphs.d.ts +1 -8
- package/dist/src/db/queries/subgraphs.js +1 -9
- package/dist/src/db/queries/subgraphs.js.map +3 -3
- package/dist/src/errors.d.ts +5 -2
- package/dist/src/errors.js +5 -5
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index.d.ts +14 -8
- package/dist/src/index.js +12 -13
- package/dist/src/index.js.map +6 -6
- package/dist/src/runtime/index.js +2 -2
- package/dist/src/runtime/index.js.map +3 -3
- package/dist/src/schemas/index.d.ts +0 -6
- package/dist/src/schemas/index.js +2 -3
- package/dist/src/schemas/index.js.map +3 -3
- package/dist/src/schemas/subgraphs.d.ts +0 -6
- package/dist/src/schemas/subgraphs.js +2 -3
- package/dist/src/schemas/subgraphs.js.map +3 -3
- package/dist/src/subgraphs/spec.d.ts +9 -0
- package/dist/src/subgraphs/spec.js +7 -7
- package/dist/src/subgraphs/spec.js.map +3 -3
- package/package.json +1 -1
package/dist/src/errors.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"export const ErrorCodes = {\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tPAYMENT_REQUIRED: \"PAYMENT_REQUIRED\",\n\tFORBIDDEN: \"FORBIDDEN\",\n\tVERSION_CONFLICT: \"VERSION_CONFLICT\",\n\tNOT_FOUND: \"NOT_FOUND\",\n\t// Tenant lifecycle (CLI surfaces these verbatim)\n\tKEY_ROTATED: \"KEY_ROTATED\",\n\tTENANT_SUSPENDED: \"TENANT_SUSPENDED\",\n\tNO_TENANT_FOR_PROJECT: \"NO_TENANT_FOR_PROJECT\",\n\tINSTANCE_EXISTS: \"INSTANCE_EXISTS\",\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n/** Base error class for all Secondlayer errors. */\nexport class SecondLayerError extends Error {\n\tpublic code: ErrorCode;\n\tpublic override cause?: unknown;\n\t/** Optional structured payload merged into the HTTP error body (machine-readable hints). */\n\tpublic details?: Record<string, unknown>;\n\n\tconstructor(\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tcause?: unknown,\n\t\tdetails?: Record<string, unknown>,\n\t) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t\tthis.details = details;\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t\tdetails: Record<string, unknown> | undefined;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\tstack: this.stack,\n\t\t\tcause: this.cause,\n\t\t\tdetails: this.details,\n\t\t};\n\t}\n}\n\nexport class NotFoundError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"NOT_FOUND\", message);\n\t}\n}\n\nexport class ValidationError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"VALIDATION_ERROR\", message, cause);\n\t}\n}\n\nexport class DatabaseError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"DATABASE_ERROR\", message, cause);\n\t}\n}\n\nexport class AuthenticationError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHENTICATION_ERROR\", message);\n\t}\n}\n\nexport class AuthorizationError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"AUTHORIZATION_ERROR\", message, undefined, details);\n\t}\n}\n\nexport class RateLimitError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"RATE_LIMIT_ERROR\", message);\n\t}\n}\n\n/**\n * HTTP 402. Carries the x402 challenge (or a retry-later reason) in `details` so\n * the global error handler emits it in the body. The wire `PAYMENT-REQUIRED`\n * header is set separately by the x402 middleware on the challenge path.\n */\nexport class PaymentRequiredError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"PAYMENT_REQUIRED\", message, undefined, details);\n\t}\n}\n\nexport class ForbiddenError extends SecondLayerError {\n\tconstructor(message = \"Forbidden\") {\n\t\tsuper(\"FORBIDDEN\", message);\n\t}\n}\n\nexport class VersionConflictError extends SecondLayerError {\n\tpublic currentVersion: string;\n\tpublic expectedVersion: string;\n\n\tconstructor(currentVersion: string, expectedVersion: string) {\n\t\tsuper(\n\t\t\t\"VERSION_CONFLICT\",\n\t\t\t`Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t\t);\n\t\tthis.currentVersion = currentVersion;\n\t\tthis.expectedVersion = expectedVersion;\n\t}\n}\n\nexport class KeyRotatedError extends SecondLayerError {\n\tconstructor(message = \"Token has been rotated\") {\n\t\tsuper(\"KEY_ROTATED\", message);\n\t}\n}\n\nexport class TenantSuspendedError extends SecondLayerError {\n\tconstructor(message = \"Instance is suspended\") {\n\t\tsuper(\"TENANT_SUSPENDED\", message);\n\t}\n}\n\n/** Error code → HTTP status. Used by API middleware for code-based matching\n * (avoids cross-bundle instanceof failures from bunup class duplication). */\n// String literal map — codes don't have to be in the central ErrorCode\n// enum (route-local error classes can supply any code; we just map the\n// HTTP status here). This keeps cross-bundle instanceof failures out of\n// the equation.\nexport const CODE_TO_STATUS: Record<\n\tstring,\n\t400 | 401 | 402 | 403 | 404 | 409 | 422 | 423 | 429 | 503\n> = {\n\t// The chain plane has no data yet — a fresh self-host install before the\n\t// first block lands. Retryable, and not the operator's mistake, so it is a\n\t// 503 with a name rather than an opaque 500.\n\tCHAIN_DATA_UNAVAILABLE: 503,\n\tAUTHENTICATION_ERROR: 401,\n\tAUTHORIZATION_ERROR: 403,\n\tPAYMENT_REQUIRED: 402,\n\tRATE_LIMIT_ERROR: 429,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tVALIDATION_ERROR: 400,\n\tKEY_ROTATED: 401,\n\tTENANT_SUSPENDED: 423,\n\tNO_TENANT_FOR_PROJECT: 404,\n\tINSTANCE_EXISTS: 409,\n\tSUBGRAPH_NOT_FOUND: 404,\n\
|
|
5
|
+
"export const ErrorCodes = {\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tPAYMENT_REQUIRED: \"PAYMENT_REQUIRED\",\n\tFORBIDDEN: \"FORBIDDEN\",\n\tVERSION_CONFLICT: \"VERSION_CONFLICT\",\n\tNOT_FOUND: \"NOT_FOUND\",\n\t// Tenant lifecycle (CLI surfaces these verbatim)\n\tKEY_ROTATED: \"KEY_ROTATED\",\n\tTENANT_SUSPENDED: \"TENANT_SUSPENDED\",\n\tNO_TENANT_FOR_PROJECT: \"NO_TENANT_FOR_PROJECT\",\n\tINSTANCE_EXISTS: \"INSTANCE_EXISTS\",\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n/** Base error class for all Secondlayer errors. */\nexport class SecondLayerError extends Error {\n\tpublic code: ErrorCode;\n\tpublic override cause?: unknown;\n\t/** Optional structured payload merged into the HTTP error body (machine-readable hints). */\n\tpublic details?: Record<string, unknown>;\n\n\tconstructor(\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tcause?: unknown,\n\t\tdetails?: Record<string, unknown>,\n\t) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t\tthis.details = details;\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t\tdetails: Record<string, unknown> | undefined;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\tstack: this.stack,\n\t\t\tcause: this.cause,\n\t\t\tdetails: this.details,\n\t\t};\n\t}\n}\n\nexport class NotFoundError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"NOT_FOUND\", message);\n\t}\n}\n\nexport class ValidationError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"VALIDATION_ERROR\", message, cause);\n\t}\n}\n\nexport class DatabaseError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"DATABASE_ERROR\", message, cause);\n\t}\n}\n\nexport class AuthenticationError extends SecondLayerError {\n\t/** `details` is merged into the HTTP body — use it to carry the recovery\n\t * hint (which credential, where it comes from) instead of a bare \"invalid\n\t * key\" the caller cannot act on. */\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"AUTHENTICATION_ERROR\", message, undefined, details);\n\t}\n}\n\nexport class AuthorizationError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"AUTHORIZATION_ERROR\", message, undefined, details);\n\t}\n}\n\nexport class RateLimitError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"RATE_LIMIT_ERROR\", message);\n\t}\n}\n\n/**\n * HTTP 402. Carries the x402 challenge (or a retry-later reason) in `details` so\n * the global error handler emits it in the body. The wire `PAYMENT-REQUIRED`\n * header is set separately by the x402 middleware on the challenge path.\n */\nexport class PaymentRequiredError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"PAYMENT_REQUIRED\", message, undefined, details);\n\t}\n}\n\nexport class ForbiddenError extends SecondLayerError {\n\tconstructor(message = \"Forbidden\") {\n\t\tsuper(\"FORBIDDEN\", message);\n\t}\n}\n\nexport class VersionConflictError extends SecondLayerError {\n\tpublic currentVersion: string;\n\tpublic expectedVersion: string;\n\n\tconstructor(currentVersion: string, expectedVersion: string) {\n\t\tsuper(\n\t\t\t\"VERSION_CONFLICT\",\n\t\t\t`Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t\t);\n\t\tthis.currentVersion = currentVersion;\n\t\tthis.expectedVersion = expectedVersion;\n\t}\n}\n\nexport class KeyRotatedError extends SecondLayerError {\n\tconstructor(message = \"Token has been rotated\") {\n\t\tsuper(\"KEY_ROTATED\", message);\n\t}\n}\n\nexport class TenantSuspendedError extends SecondLayerError {\n\tconstructor(message = \"Instance is suspended\") {\n\t\tsuper(\"TENANT_SUSPENDED\", message);\n\t}\n}\n\n/** Error code → HTTP status. Used by API middleware for code-based matching\n * (avoids cross-bundle instanceof failures from bunup class duplication). */\n// String literal map — codes don't have to be in the central ErrorCode\n// enum (route-local error classes can supply any code; we just map the\n// HTTP status here). This keeps cross-bundle instanceof failures out of\n// the equation.\nexport const CODE_TO_STATUS: Record<\n\tstring,\n\t400 | 401 | 402 | 403 | 404 | 409 | 415 | 422 | 423 | 429 | 503\n> = {\n\t// The chain plane has no data yet — a fresh self-host install before the\n\t// first block lands. Retryable, and not the operator's mistake, so it is a\n\t// 503 with a name rather than an opaque 500.\n\tCHAIN_DATA_UNAVAILABLE: 503,\n\tAUTHENTICATION_ERROR: 401,\n\tAUTHORIZATION_ERROR: 403,\n\tPAYMENT_REQUIRED: 402,\n\tRATE_LIMIT_ERROR: 429,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tVALIDATION_ERROR: 400,\n\tKEY_ROTATED: 401,\n\tTENANT_SUSPENDED: 423,\n\tNO_TENANT_FOR_PROJECT: 404,\n\tINSTANCE_EXISTS: 409,\n\tSUBGRAPH_NOT_FOUND: 404,\n\tGHOST_KEY_READ_ONLY: 403,\n\t// A write that did not declare `Content-Type: application/json`. Shaped\n\t// like something a browser could have forged cross-origin without a CORS\n\t// preflight — see the API's `middleware/csrf.ts`.\n\tUNSUPPORTED_MEDIA_TYPE: 415,\n} as const;\n\nexport function getErrorMessage(err: unknown): string {\n\treturn err instanceof Error ? err.message : String(err);\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAO,IAAM,aAAa;AAAA,EACzB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,WAAW;AAAA,EAEX,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,iBAAiB;AAClB;AAAA;AAKO,MAAM,yBAAyB,MAAM;AAAA,EACpC;AAAA,EACS;AAAA,EAET;AAAA,EAEP,WAAW,CACV,MACA,SACA,OACA,SACC;AAAA,IACD,MAAM,OAAO;AAAA,IACb,KAAK,OAAO;AAAA,IACZ,KAAK,QAAQ;AAAA,IACb,KAAK,UAAU;AAAA,IACf,KAAK,OAAO,KAAK,YAAY;AAAA,IAC7B,MAAM,oBAAoB,MAAM,KAAK,WAAW;AAAA;AAAA,EAGjD,MAAM,GAOJ;AAAA,IACD,OAAO;AAAA,MACN,MAAM,KAAK;AAAA,MACX,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,OAAO,KAAK;AAAA,MACZ,SAAS,KAAK;A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AAA;AAEO,MAAM,wBAAwB,iBAAiB;AAAA,EACrD,WAAW,CAAC,UAAU,0BAA0B;AAAA,IAC/C,MAAM,eAAe,OAAO;AAAA;AAE9B;AAAA;AAEO,MAAM,6BAA6B,iBAAiB;AAAA,EAC1D,WAAW,CAAC,UAAU,yBAAyB;AAAA,IAC9C,MAAM,oBAAoB,OAAO;AAAA;AAEnC;AAQO,IAAM,iBAGT;AAAA,EAIH,wBAAwB;AAAA,EACxB,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EAIrB,wBAAwB;AACzB;AAEO,SAAS,eAAe,CAAC,KAAsB;AAAA,EACrD,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA;",
|
|
8
|
+
"debugId": "D8A474DF7664F17764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2119,7 +2119,10 @@ declare class DatabaseError extends SecondLayerError {
|
|
|
2119
2119
|
constructor(message: string, cause?: unknown);
|
|
2120
2120
|
}
|
|
2121
2121
|
declare class AuthenticationError extends SecondLayerError {
|
|
2122
|
-
|
|
2122
|
+
/** `details` is merged into the HTTP body — use it to carry the recovery
|
|
2123
|
+
* hint (which credential, where it comes from) instead of a bare "invalid
|
|
2124
|
+
* key" the caller cannot act on. */
|
|
2125
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
2123
2126
|
}
|
|
2124
2127
|
declare class AuthorizationError extends SecondLayerError {
|
|
2125
2128
|
constructor(message: string, details?: Record<string, unknown>);
|
|
@@ -2151,7 +2154,7 @@ declare class TenantSuspendedError extends SecondLayerError {
|
|
|
2151
2154
|
}
|
|
2152
2155
|
/** Error code → HTTP status. Used by API middleware for code-based matching
|
|
2153
2156
|
* (avoids cross-bundle instanceof failures from bunup class duplication). */
|
|
2154
|
-
declare const CODE_TO_STATUS: Record<string, 400 | 401 | 402 | 403 | 404 | 409 | 422 | 423 | 429 | 503>;
|
|
2157
|
+
declare const CODE_TO_STATUS: Record<string, 400 | 401 | 402 | 403 | 404 | 409 | 415 | 422 | 423 | 429 | 503>;
|
|
2155
2158
|
declare function getErrorMessage(err: unknown): string;
|
|
2156
2159
|
declare class Logger {
|
|
2157
2160
|
private _level?;
|
|
@@ -2182,18 +2185,12 @@ interface DeploySubgraphRequest {
|
|
|
2182
2185
|
sourceCode?: string;
|
|
2183
2186
|
/** Validate the definition + print the DDL plan without deploying. */
|
|
2184
2187
|
dryRun?: boolean;
|
|
2185
|
-
/**
|
|
2186
|
-
* Read visibility. Server-side default: deploys → public (anon reads on
|
|
2187
|
-
* /v1/subgraphs, name claimed in the global public namespace).
|
|
2188
|
-
*/
|
|
2189
|
-
visibility?: "public" | "private";
|
|
2190
2188
|
}
|
|
2191
2189
|
declare const DeploySubgraphRequestSchema: z2.ZodType<DeploySubgraphRequest>;
|
|
2192
2190
|
interface DeploySubgraphResponse {
|
|
2193
2191
|
action: "created" | "unchanged" | "handler_updated" | "updated" | "reindexed";
|
|
2194
2192
|
subgraphId: string;
|
|
2195
2193
|
version: string;
|
|
2196
|
-
visibility?: "public" | "private";
|
|
2197
2194
|
message: string;
|
|
2198
2195
|
/** Effective indexing start height. */
|
|
2199
2196
|
start_block?: number;
|
|
@@ -2628,6 +2625,15 @@ type SubgraphSpecFormat = "openapi" | "agent" | "markdown";
|
|
|
2628
2625
|
interface SubgraphSpecOptions {
|
|
2629
2626
|
serverUrl?: string;
|
|
2630
2627
|
generatedAt?: string;
|
|
2628
|
+
/**
|
|
2629
|
+
* Self-hosted instances ignore the `visibility` column when deciding
|
|
2630
|
+
* whether a read needs a key (`/v1/subgraphs` auth is the loopback rule,
|
|
2631
|
+
* not the flag) — but this generator still branched on it, so a spec built
|
|
2632
|
+
* for a self-hosted deploy pointed readers at the authenticated `/api`
|
|
2633
|
+
* path for a read that was actually open. Callers on that mode should set
|
|
2634
|
+
* this so the generated URLs match the auth the API actually enforces.
|
|
2635
|
+
*/
|
|
2636
|
+
forcePublicRead?: boolean;
|
|
2631
2637
|
}
|
|
2632
2638
|
interface SubgraphAgentSchema {
|
|
2633
2639
|
name: string;
|
package/dist/src/index.js
CHANGED
|
@@ -1023,8 +1023,8 @@ class DatabaseError extends SecondLayerError {
|
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
1025
|
class AuthenticationError extends SecondLayerError {
|
|
1026
|
-
constructor(message) {
|
|
1027
|
-
super("AUTHENTICATION_ERROR", message);
|
|
1026
|
+
constructor(message, details) {
|
|
1027
|
+
super("AUTHENTICATION_ERROR", message, undefined, details);
|
|
1028
1028
|
}
|
|
1029
1029
|
}
|
|
1030
1030
|
|
|
@@ -1087,8 +1087,8 @@ var CODE_TO_STATUS = {
|
|
|
1087
1087
|
NO_TENANT_FOR_PROJECT: 404,
|
|
1088
1088
|
INSTANCE_EXISTS: 409,
|
|
1089
1089
|
SUBGRAPH_NOT_FOUND: 404,
|
|
1090
|
-
|
|
1091
|
-
|
|
1090
|
+
GHOST_KEY_READ_ONLY: 403,
|
|
1091
|
+
UNSUPPORTED_MEDIA_TYPE: 415
|
|
1092
1092
|
};
|
|
1093
1093
|
function getErrorMessage(err) {
|
|
1094
1094
|
return err instanceof Error ? err.message : String(err);
|
|
@@ -1105,8 +1105,7 @@ var DeploySubgraphRequestSchema = z2.object({
|
|
|
1105
1105
|
handlerCode: z2.string().max(1048576, "handler code exceeds 1MB limit"),
|
|
1106
1106
|
startBlock: z2.number().int().nonnegative().optional(),
|
|
1107
1107
|
sourceCode: z2.string().max(1048576, "source code exceeds 1MB limit").optional(),
|
|
1108
|
-
dryRun: z2.boolean().optional()
|
|
1109
|
-
visibility: z2.enum(["public", "private"]).optional()
|
|
1108
|
+
dryRun: z2.boolean().optional()
|
|
1110
1109
|
});
|
|
1111
1110
|
|
|
1112
1111
|
// src/schemas/subscriptions.ts
|
|
@@ -1482,14 +1481,14 @@ var SYSTEM_COLUMNS = ["_id", "_block_height", "_tx_id", "_created_at"];
|
|
|
1482
1481
|
var BASE_QUERY_PARAMS = ["_limit", "_offset", "_sort", "_order", "_fields"];
|
|
1483
1482
|
var PUBLIC_BASE_QUERY_PARAMS = ["_limit", "cursor", "_order", "_fields"];
|
|
1484
1483
|
var COMPARISON_OPS = ["neq", "gt", "gte", "lt", "lte"];
|
|
1485
|
-
function isPublicRead(detail) {
|
|
1486
|
-
return detail.visibility === "public";
|
|
1484
|
+
function isPublicRead(detail, options) {
|
|
1485
|
+
return options.forcePublicRead ?? detail.visibility === "public";
|
|
1487
1486
|
}
|
|
1488
1487
|
function generatedAt(options) {
|
|
1489
1488
|
return options.generatedAt ?? new Date().toISOString();
|
|
1490
1489
|
}
|
|
1491
1490
|
function normalizeServerUrl(serverUrl) {
|
|
1492
|
-
return (serverUrl ?? "
|
|
1491
|
+
return (serverUrl ?? "http://127.0.0.1:3800").replace(/\/+$/, "");
|
|
1493
1492
|
}
|
|
1494
1493
|
function tablePath(subgraphName, tableName, publicRead) {
|
|
1495
1494
|
const base = publicRead ? "/v1/subgraphs" : "/api/subgraphs";
|
|
@@ -1676,7 +1675,7 @@ function tableParameters(table, publicRead) {
|
|
|
1676
1675
|
}
|
|
1677
1676
|
function generateSubgraphAgentSchema(detail, options = {}) {
|
|
1678
1677
|
const serverUrl = normalizeServerUrl(options.serverUrl);
|
|
1679
|
-
const publicRead = isPublicRead(detail);
|
|
1678
|
+
const publicRead = isPublicRead(detail, options);
|
|
1680
1679
|
const tables = {};
|
|
1681
1680
|
for (const [tableName, table] of Object.entries(detail.tables)) {
|
|
1682
1681
|
const path = tablePath(detail.name, tableName, publicRead);
|
|
@@ -1718,7 +1717,7 @@ function generateSubgraphAgentSchema(detail, options = {}) {
|
|
|
1718
1717
|
}
|
|
1719
1718
|
function generateSubgraphOpenApi(detail, options = {}) {
|
|
1720
1719
|
const serverUrl = normalizeServerUrl(options.serverUrl);
|
|
1721
|
-
const publicRead = isPublicRead(detail);
|
|
1720
|
+
const publicRead = isPublicRead(detail, options);
|
|
1722
1721
|
const paths = {};
|
|
1723
1722
|
const schemas = {};
|
|
1724
1723
|
for (const [tableName, table] of Object.entries(detail.tables)) {
|
|
@@ -1830,7 +1829,7 @@ function generateSubgraphOpenApi(detail, options = {}) {
|
|
|
1830
1829
|
}
|
|
1831
1830
|
function generateSubgraphMarkdown(detail, options = {}) {
|
|
1832
1831
|
const agent = generateSubgraphAgentSchema(detail, options);
|
|
1833
|
-
const publicRead = isPublicRead(detail);
|
|
1832
|
+
const publicRead = isPublicRead(detail, options);
|
|
1834
1833
|
const lines = [
|
|
1835
1834
|
`# ${detail.name} Subgraph API`,
|
|
1836
1835
|
"",
|
|
@@ -2148,5 +2147,5 @@ export {
|
|
|
2148
2147
|
AuthenticationError
|
|
2149
2148
|
};
|
|
2150
2149
|
|
|
2151
|
-
//# debugId=
|
|
2150
|
+
//# debugId=CC94EE7EB04C7F8864756E2164756E21
|
|
2152
2151
|
//# sourceMappingURL=index.js.map
|