@kubohiroya/turbowarp-http-server 0.1.0 → 0.2.1
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/README.ja.md +29 -13
- package/README.md +101 -42
- package/dist/cli.js +131 -17
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapters/cloudflare.d.ts +2 -0
- package/dist/compiler/adapters/cloudflare.js +477 -0
- package/dist/compiler/adapters/cloudflare.js.map +1 -0
- package/dist/compiler/adapters/firebase.d.ts +2 -0
- package/dist/compiler/adapters/firebase.js +489 -0
- package/dist/compiler/adapters/firebase.js.map +1 -0
- package/dist/compiler/adapters/index.d.ts +2 -0
- package/dist/compiler/adapters/index.js +3 -0
- package/dist/compiler/adapters/index.js.map +1 -0
- package/dist/compiler/binary/codec.d.ts +4 -0
- package/dist/compiler/binary/codec.js +45 -0
- package/dist/compiler/binary/codec.js.map +1 -0
- package/dist/compiler/binary/error.d.ts +3 -0
- package/dist/compiler/binary/error.js +21 -0
- package/dist/compiler/binary/error.js.map +1 -0
- package/dist/compiler/binary/index.d.ts +4 -0
- package/dist/compiler/binary/index.js +5 -0
- package/dist/compiler/binary/index.js.map +1 -0
- package/dist/compiler/binary/runtime.d.ts +18 -0
- package/dist/compiler/binary/runtime.js +123 -0
- package/dist/compiler/binary/runtime.js.map +1 -0
- package/dist/compiler/binary/types.d.ts +17 -0
- package/dist/compiler/binary/types.js +2 -0
- package/dist/compiler/binary/types.js.map +1 -0
- package/dist/compiler/feature-flags.d.ts +4 -0
- package/dist/compiler/feature-flags.js +4 -0
- package/dist/compiler/feature-flags.js.map +1 -0
- package/dist/compiler/index.d.ts +35 -0
- package/dist/compiler/index.js +84 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/ir-v2/canonical.d.ts +3 -0
- package/dist/compiler/ir-v2/canonical.js +50 -0
- package/dist/compiler/ir-v2/canonical.js.map +1 -0
- package/dist/compiler/ir-v2/index.d.ts +4 -0
- package/dist/compiler/ir-v2/index.js +5 -0
- package/dist/compiler/ir-v2/index.js.map +1 -0
- package/dist/compiler/ir-v2/parse.d.ts +10 -0
- package/dist/compiler/ir-v2/parse.js +753 -0
- package/dist/compiler/ir-v2/parse.js.map +1 -0
- package/dist/compiler/ir-v2/strict-json.d.ts +4 -0
- package/dist/compiler/ir-v2/strict-json.js +133 -0
- package/dist/compiler/ir-v2/strict-json.js.map +1 -0
- package/dist/compiler/ir-v2/types.d.ts +412 -0
- package/dist/compiler/ir-v2/types.js +84 -0
- package/dist/compiler/ir-v2/types.js.map +1 -0
- package/dist/compiler/kvs/lowering.d.ts +13 -0
- package/dist/compiler/kvs/lowering.js +77 -0
- package/dist/compiler/kvs/lowering.js.map +1 -0
- package/dist/compiler/manifest/error.d.ts +7 -0
- package/dist/compiler/manifest/error.js +9 -0
- package/dist/compiler/manifest/error.js.map +1 -0
- package/dist/compiler/manifest/index.d.ts +6 -0
- package/dist/compiler/manifest/index.js +7 -0
- package/dist/compiler/manifest/index.js.map +1 -0
- package/dist/compiler/manifest/operations.d.ts +12 -0
- package/dist/compiler/manifest/operations.js +60 -0
- package/dist/compiler/manifest/operations.js.map +1 -0
- package/dist/compiler/manifest/parse.d.ts +9 -0
- package/dist/compiler/manifest/parse.js +280 -0
- package/dist/compiler/manifest/parse.js.map +1 -0
- package/dist/compiler/manifest/registry.d.ts +3 -0
- package/dist/compiler/manifest/registry.js +48 -0
- package/dist/compiler/manifest/registry.js.map +1 -0
- package/dist/compiler/manifest/resolve.d.ts +14 -0
- package/dist/compiler/manifest/resolve.js +116 -0
- package/dist/compiler/manifest/resolve.js.map +1 -0
- package/dist/compiler/manifest/types.d.ts +95 -0
- package/dist/compiler/manifest/types.js +3 -0
- package/dist/compiler/manifest/types.js.map +1 -0
- package/dist/compiler/named-body/index.d.ts +1 -0
- package/dist/compiler/named-body/index.js +2 -0
- package/dist/compiler/named-body/index.js.map +1 -0
- package/dist/compiler/named-body/lowering.d.ts +18 -0
- package/dist/compiler/named-body/lowering.js +83 -0
- package/dist/compiler/named-body/lowering.js.map +1 -0
- package/dist/compiler/pipeline/compiler.d.ts +18 -0
- package/dist/compiler/pipeline/compiler.js +105 -0
- package/dist/compiler/pipeline/compiler.js.map +1 -0
- package/dist/compiler/pipeline/core-generator.d.ts +3 -0
- package/dist/compiler/pipeline/core-generator.js +483 -0
- package/dist/compiler/pipeline/core-generator.js.map +1 -0
- package/dist/compiler/pipeline/index.d.ts +5 -0
- package/dist/compiler/pipeline/index.js +6 -0
- package/dist/compiler/pipeline/index.js.map +1 -0
- package/dist/compiler/pipeline/registry.d.ts +7 -0
- package/dist/compiler/pipeline/registry.js +17 -0
- package/dist/compiler/pipeline/registry.js.map +1 -0
- package/dist/compiler/pipeline/requirements.d.ts +9 -0
- package/dist/compiler/pipeline/requirements.js +135 -0
- package/dist/compiler/pipeline/requirements.js.map +1 -0
- package/dist/compiler/pipeline/types.d.ts +65 -0
- package/dist/compiler/pipeline/types.js +2 -0
- package/dist/compiler/pipeline/types.js.map +1 -0
- package/dist/compiler/runtime/error.d.ts +6 -0
- package/dist/compiler/runtime/error.js +9 -0
- package/dist/compiler/runtime/error.js.map +1 -0
- package/dist/compiler/runtime/index.d.ts +1 -0
- package/dist/compiler/runtime/index.js +2 -0
- package/dist/compiler/runtime/index.js.map +1 -0
- package/dist/compiler/structured-data/index.d.ts +3 -0
- package/dist/compiler/structured-data/index.js +4 -0
- package/dist/compiler/structured-data/index.js.map +1 -0
- package/dist/compiler/structured-data/lowering.d.ts +30 -0
- package/dist/compiler/structured-data/lowering.js +202 -0
- package/dist/compiler/structured-data/lowering.js.map +1 -0
- package/dist/compiler/structured-data/path.d.ts +2 -0
- package/dist/compiler/structured-data/path.js +60 -0
- package/dist/compiler/structured-data/path.js.map +1 -0
- package/dist/compiler/structured-data/runtime.d.ts +20 -0
- package/dist/compiler/structured-data/runtime.js +210 -0
- package/dist/compiler/structured-data/runtime.js.map +1 -0
- package/dist/compiler/turbowarp-v2.d.ts +8 -0
- package/dist/compiler/turbowarp-v2.js +479 -0
- package/dist/compiler/turbowarp-v2.js.map +1 -0
- package/dist/compiler/validator/index.d.ts +4 -0
- package/dist/compiler/validator/index.js +5 -0
- package/dist/compiler/validator/index.js.map +1 -0
- package/dist/compiler/validator/ir-validator.d.ts +10 -0
- package/dist/compiler/validator/ir-validator.js +463 -0
- package/dist/compiler/validator/ir-validator.js.map +1 -0
- package/dist/compiler/validator/resource-lifetime.d.ts +18 -0
- package/dist/compiler/validator/resource-lifetime.js +106 -0
- package/dist/compiler/validator/resource-lifetime.js.map +1 -0
- package/dist/compiler/validator/turbowarp-subset.d.ts +3 -0
- package/dist/compiler/validator/turbowarp-subset.js +241 -0
- package/dist/compiler/validator/turbowarp-subset.js.map +1 -0
- package/dist/compiler/validator/types.d.ts +30 -0
- package/dist/compiler/validator/types.js +7 -0
- package/dist/compiler/validator/types.js.map +1 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/digest-cli.js +0 -0
- package/dist/extension-manifest.json +102 -0
- package/dist/named-body.d.ts +57 -0
- package/dist/named-body.js +396 -0
- package/dist/named-body.js.map +1 -0
- package/dist/named-data-namespace.d.ts +3 -0
- package/dist/named-data-namespace.js +6 -0
- package/dist/named-data-namespace.js.map +1 -0
- package/dist/protocol.d.ts +13 -1
- package/dist/protocol.js +34 -0
- package/dist/protocol.js.map +1 -1
- package/dist/resource-named-body-provider.d.ts +8 -0
- package/dist/resource-named-body-provider.js +88 -0
- package/dist/resource-named-body-provider.js.map +1 -0
- package/dist/server.d.ts +10 -1
- package/dist/server.js +37 -7
- package/dist/server.js.map +1 -1
- package/dist/turbowarp-http-server.js +516 -1
- package/docs/binary-resource-semantics.ja.md +84 -0
- package/docs/cloudflare-worker-compiler.ja.md +90 -0
- package/docs/compiler-manifest-registry.ja.md +79 -0
- package/docs/compiler-platform-pipeline.ja.md +94 -0
- package/docs/deploy-ir-v2.ja.md +123 -0
- package/docs/fixed-input-editors.ja.md +23 -0
- package/docs/index.html +80 -0
- package/docs/ir-v2-conformance.ja.md +65 -0
- package/docs/named-response-body.ja.md +120 -0
- package/docs/platform-storage-adapters.ja.md +99 -0
- package/docs/server-executable-subset.ja.md +88 -0
- package/docs/structured-data-lowering.ja.md +63 -0
- package/examples/compiler/message-app.v2.ir.json +41 -0
- package/package.json +44 -20
- package/schemas/block-editor-fixed-inputs.schema.json +85 -0
- package/schemas/compiler-extension-manifest.schema.json +126 -0
- package/schemas/compiler-manifest-lock-v1.schema.json +48 -0
- package/schemas/deploy-ir-v2.schema.json +835 -0
- package/schemas/ir-v2-conformance-fixture.schema.json +44 -0
- package/src/block-definitions.json +76 -0
- package/src/cli.ts +136 -23
- package/src/compiler/adapters/cloudflare.ts +510 -0
- package/src/compiler/adapters/firebase.ts +538 -0
- package/src/compiler/adapters/index.ts +2 -0
- package/src/compiler/binary/codec.ts +61 -0
- package/src/compiler/binary/error.ts +25 -0
- package/src/compiler/binary/index.ts +4 -0
- package/src/compiler/binary/runtime.ts +133 -0
- package/src/compiler/binary/types.ts +26 -0
- package/src/compiler/feature-flags.ts +7 -0
- package/src/compiler/index.ts +114 -0
- package/src/compiler/ir-v2/canonical.ts +46 -0
- package/src/compiler/ir-v2/index.ts +9 -0
- package/src/compiler/ir-v2/parse.ts +921 -0
- package/src/compiler/ir-v2/strict-json.ts +129 -0
- package/src/compiler/ir-v2/types.ts +462 -0
- package/src/compiler/kvs/lowering.ts +88 -0
- package/src/compiler/manifest/error.ts +29 -0
- package/src/compiler/manifest/index.ts +17 -0
- package/src/compiler/manifest/operations.ts +175 -0
- package/src/compiler/manifest/parse.ts +390 -0
- package/src/compiler/manifest/registry.ts +74 -0
- package/src/compiler/manifest/resolve.ts +159 -0
- package/src/compiler/manifest/types.ts +112 -0
- package/src/compiler/named-body/index.ts +1 -0
- package/src/compiler/named-body/lowering.ts +186 -0
- package/src/compiler/pipeline/compiler.ts +138 -0
- package/src/compiler/pipeline/core-generator.ts +486 -0
- package/src/compiler/pipeline/index.ts +5 -0
- package/src/compiler/pipeline/registry.ts +18 -0
- package/src/compiler/pipeline/requirements.ts +139 -0
- package/src/compiler/pipeline/types.ts +59 -0
- package/src/compiler/runtime/error.ts +11 -0
- package/src/compiler/runtime/index.ts +1 -0
- package/src/compiler/structured-data/index.ts +3 -0
- package/src/compiler/structured-data/lowering.ts +314 -0
- package/src/compiler/structured-data/path.ts +53 -0
- package/src/compiler/structured-data/runtime.ts +221 -0
- package/src/compiler/turbowarp-v2.ts +610 -0
- package/src/compiler/validator/index.ts +4 -0
- package/src/compiler/validator/ir-validator.ts +812 -0
- package/src/compiler/validator/resource-lifetime.ts +153 -0
- package/src/compiler/validator/turbowarp-subset.ts +387 -0
- package/src/compiler/validator/types.ts +68 -0
- package/src/extension.ts +87 -1
- package/src/fixed-input-editors.ts +181 -0
- package/src/fixed-input-schema.ts +15 -0
- package/src/named-body.ts +495 -0
- package/src/named-data-namespace.ts +6 -0
- package/src/protocol.ts +50 -1
- package/src/resource-named-body-provider.ts +106 -0
- package/src/server.ts +88 -8
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.html +0 -32
- package/docs/turbowarp-http-server.architecture.visual-check.json +0 -547
- package/schemas/extension-manifest.schema.json +0 -49
- package/src/extension-manifest.ts +0 -149
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { findCapabilityOrigin } from '../pipeline/requirements.js';
|
|
2
|
+
export const firebaseFunctionsAdapter = {
|
|
3
|
+
id: 'firebase-functions',
|
|
4
|
+
version: '1.3.0',
|
|
5
|
+
capabilities: () => ({
|
|
6
|
+
keys: ['key-value-store', 'object-storage', 'record-store', 'request-metadata:client-address', 'streaming-body'],
|
|
7
|
+
maxBinaryBytes: 10000000
|
|
8
|
+
}),
|
|
9
|
+
plan({ ir, requirements, config }) {
|
|
10
|
+
const unsupported = requirements.keys.filter((requirement) => !firebaseFunctionsAdapter.capabilities().keys.includes(requirement));
|
|
11
|
+
if (unsupported.length > 0) {
|
|
12
|
+
return {
|
|
13
|
+
ok: false,
|
|
14
|
+
diagnostics: unsupported.map((requirement) => capabilityDiagnostic(requirement, ir))
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const parsed = parseConfig(config);
|
|
18
|
+
if ('diagnostic' in parsed)
|
|
19
|
+
return { ok: false, diagnostics: [parsed.diagnostic] };
|
|
20
|
+
return {
|
|
21
|
+
ok: true,
|
|
22
|
+
plan: {
|
|
23
|
+
targetId: firebaseFunctionsAdapter.id,
|
|
24
|
+
adapterVersion: firebaseFunctionsAdapter.version,
|
|
25
|
+
requirements: requirements.keys,
|
|
26
|
+
bindings: {
|
|
27
|
+
...(requirements.keys.includes('record-store') ? { recordCollection: parsed.recordCollection } : {}),
|
|
28
|
+
...(requirements.keys.includes('key-value-store')
|
|
29
|
+
? { keyValueCollection: parsed.keyValueCollection }
|
|
30
|
+
: {}),
|
|
31
|
+
...(requirements.keys.includes('object-storage') ? { objectBucketEnv: parsed.objectBucketEnv } : {}),
|
|
32
|
+
functionName: parsed.functionName
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
generate({ ir, plan, core }) {
|
|
38
|
+
return {
|
|
39
|
+
...relocateCore(core),
|
|
40
|
+
'functions/package.json': functionsPackage(ir),
|
|
41
|
+
'functions/tsconfig.json': functionsTsconfig(),
|
|
42
|
+
'functions/src/index.ts': indexSource(plan),
|
|
43
|
+
'functions/src/platform.ts': platformSource(),
|
|
44
|
+
'firebase.json': firebaseJson(),
|
|
45
|
+
'.firebaserc.example': firebaserc(),
|
|
46
|
+
'firestore.rules': denyAllRules('cloud.firestore'),
|
|
47
|
+
'firestore.indexes.json': firestoreIndexes(plan),
|
|
48
|
+
'storage.rules': denyAllRules('firebase.storage'),
|
|
49
|
+
'README.md': generatedReadme(plan)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function parseConfig(config) {
|
|
54
|
+
const defaults = {
|
|
55
|
+
functionName: 'api',
|
|
56
|
+
keyValueCollection: 'key_values',
|
|
57
|
+
objectBucketEnv: 'ASSET_BUCKET',
|
|
58
|
+
recordCollection: 'records'
|
|
59
|
+
};
|
|
60
|
+
if (config === undefined || config === null)
|
|
61
|
+
return defaults;
|
|
62
|
+
if (typeof config !== 'object' || Array.isArray(config))
|
|
63
|
+
return { diagnostic: configDiagnostic() };
|
|
64
|
+
const value = config;
|
|
65
|
+
if (Object.keys(value).some((key) => key !== 'functionName' &&
|
|
66
|
+
key !== 'keyValueCollection' &&
|
|
67
|
+
key !== 'objectBucketEnv' &&
|
|
68
|
+
key !== 'recordCollection')) {
|
|
69
|
+
return { diagnostic: configDiagnostic() };
|
|
70
|
+
}
|
|
71
|
+
const functionName = value.functionName ?? defaults.functionName;
|
|
72
|
+
const keyValueCollection = value.keyValueCollection ?? defaults.keyValueCollection;
|
|
73
|
+
const objectBucketEnv = value.objectBucketEnv ?? defaults.objectBucketEnv;
|
|
74
|
+
const recordCollection = value.recordCollection ?? defaults.recordCollection;
|
|
75
|
+
if (typeof functionName !== 'string' ||
|
|
76
|
+
typeof keyValueCollection !== 'string' ||
|
|
77
|
+
typeof objectBucketEnv !== 'string' ||
|
|
78
|
+
typeof recordCollection !== 'string' ||
|
|
79
|
+
!/^[A-Za-z][A-Za-z0-9_]{0,62}$/u.test(functionName) ||
|
|
80
|
+
!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/u.test(keyValueCollection) ||
|
|
81
|
+
!/^[A-Z][A-Z0-9_]{0,63}$/u.test(objectBucketEnv) ||
|
|
82
|
+
!/^[A-Za-z][A-Za-z0-9_-]{0,127}$/u.test(recordCollection)) {
|
|
83
|
+
return { diagnostic: configDiagnostic() };
|
|
84
|
+
}
|
|
85
|
+
return { functionName, keyValueCollection, objectBucketEnv, recordCollection };
|
|
86
|
+
}
|
|
87
|
+
function capabilityDiagnostic(requirement, ir) {
|
|
88
|
+
const origin = findCapabilityOrigin(ir, requirement);
|
|
89
|
+
return {
|
|
90
|
+
severity: 'error',
|
|
91
|
+
code: 'TW2_TARGET_CAPABILITY_UNSUPPORTED',
|
|
92
|
+
message: `Target firebase-functions does not support capability ${requirement}.`,
|
|
93
|
+
reason: 'The Firebase Functions adapter cannot satisfy this target-neutral requirement.',
|
|
94
|
+
suggestion: 'Use a target adapter that declares the capability or remove the requiring operation.',
|
|
95
|
+
targetId: 'firebase-functions',
|
|
96
|
+
...(origin === undefined ? {} : { routeId: origin.routeId }),
|
|
97
|
+
...(origin?.sourceRef === undefined ? {} : { sourceRef: origin.sourceRef })
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function configDiagnostic() {
|
|
101
|
+
return {
|
|
102
|
+
severity: 'error',
|
|
103
|
+
code: 'TW2_TARGET_CONFIG_INVALID',
|
|
104
|
+
message: 'Firebase target config is invalid.',
|
|
105
|
+
reason: 'Only functionName, keyValueCollection, objectBucketEnv, and recordCollection identifiers are accepted; secret or project values are not.',
|
|
106
|
+
suggestion: 'Use {"functionName":"api","keyValueCollection":"key_values","objectBucketEnv":"ASSET_BUCKET","recordCollection":"records"}.',
|
|
107
|
+
targetId: 'firebase-functions'
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function relocateCore(core) {
|
|
111
|
+
return Object.fromEntries(Object.entries(core.files).map(([path, source]) => [
|
|
112
|
+
path.startsWith('src/') ? `functions/${path}` : `functions/src/${path}`,
|
|
113
|
+
source
|
|
114
|
+
]));
|
|
115
|
+
}
|
|
116
|
+
function indexSource(plan) {
|
|
117
|
+
const functionName = plan.bindings.functionName ?? 'api';
|
|
118
|
+
const keyValueCollection = plan.bindings.keyValueCollection;
|
|
119
|
+
const recordCollection = plan.bindings.recordCollection;
|
|
120
|
+
const bucketEnvironment = plan.bindings.objectBucketEnv;
|
|
121
|
+
const services = [
|
|
122
|
+
...(recordCollection === undefined
|
|
123
|
+
? []
|
|
124
|
+
: [`records: () => createRecordStore(firestore, ${JSON.stringify(recordCollection)})`]),
|
|
125
|
+
...(keyValueCollection === undefined
|
|
126
|
+
? []
|
|
127
|
+
: [`keyValues: () => createKeyValueStore(firestore, ${JSON.stringify(keyValueCollection)})`]),
|
|
128
|
+
...(bucketEnvironment === undefined
|
|
129
|
+
? []
|
|
130
|
+
: [
|
|
131
|
+
`objects: () => createObjectStore(storage.bucket(process.env[${JSON.stringify(bucketEnvironment)}]))`
|
|
132
|
+
]),
|
|
133
|
+
"clientAddress: (context) => (context as {env?: {incoming?: {socket?: {remoteAddress?: string}}}}).env?.incoming?.socket?.remoteAddress ?? ''"
|
|
134
|
+
].join(',\n ');
|
|
135
|
+
return `import {getRequestListener} from '@hono/node-server';
|
|
136
|
+
import {initializeApp} from 'firebase-admin/app';
|
|
137
|
+
import {getFirestore} from 'firebase-admin/firestore';
|
|
138
|
+
import {getStorage} from 'firebase-admin/storage';
|
|
139
|
+
import {onRequest} from 'firebase-functions/v2/https';
|
|
140
|
+
import {Hono} from 'hono';
|
|
141
|
+
import {registerCoreRoutes} from './core.generated.js';
|
|
142
|
+
import {createKeyValueStore, createObjectStore, createRecordStore} from './platform.js';
|
|
143
|
+
|
|
144
|
+
initializeApp();
|
|
145
|
+
const firestore = getFirestore();
|
|
146
|
+
const storage = getStorage();
|
|
147
|
+
const app = new Hono();
|
|
148
|
+
registerCoreRoutes(app, {
|
|
149
|
+
${services}
|
|
150
|
+
});
|
|
151
|
+
const listener = getRequestListener(app.fetch);
|
|
152
|
+
export const ${functionName} = onRequest((request, response) => listener(request, response));
|
|
153
|
+
`;
|
|
154
|
+
}
|
|
155
|
+
function platformSource() {
|
|
156
|
+
return `import {createHash} from 'node:crypto';
|
|
157
|
+
import {once} from 'node:events';
|
|
158
|
+
import type {Storage} from 'firebase-admin/storage';
|
|
159
|
+
import type {BinaryBodySource, BinaryLocator, BinaryMetadata, BinaryObjectStore, BinaryRef, KeyValueStore, RecordStore} from './core.generated.js';
|
|
160
|
+
|
|
161
|
+
interface DocumentSnapshot {exists: boolean; id: string; data(): Record<string, unknown> | undefined}
|
|
162
|
+
interface DocumentReference {id: string; set(value: unknown): Promise<unknown>; get(): Promise<DocumentSnapshot>; delete(): Promise<unknown>}
|
|
163
|
+
interface QuerySnapshot {readonly docs: readonly DocumentSnapshot[]}
|
|
164
|
+
interface TransactionLike {get(document: DocumentReference): Promise<DocumentSnapshot>; delete(document: DocumentReference): TransactionLike}
|
|
165
|
+
interface QueryLike {
|
|
166
|
+
where(field: string, operator: '==', value: unknown): QueryLike;
|
|
167
|
+
orderBy(field: string, direction: 'asc' | 'desc'): QueryLike;
|
|
168
|
+
limit(value: number): QueryLike;
|
|
169
|
+
get(): Promise<QuerySnapshot>;
|
|
170
|
+
}
|
|
171
|
+
interface CollectionReference extends QueryLike {doc(id?: string): DocumentReference}
|
|
172
|
+
export interface FirestoreLike {collection(name: string): CollectionReference; runTransaction<T>(update: (transaction: TransactionLike) => Promise<T>): Promise<T>}
|
|
173
|
+
export type BucketLike = ReturnType<Storage['bucket']>;
|
|
174
|
+
type StorageMetadataValue = string | boolean | number | null;
|
|
175
|
+
interface StorageMetadata {size?: string | number; contentType?: string; generation?: string | number; metadata?: Record<string, StorageMetadataValue>}
|
|
176
|
+
|
|
177
|
+
export function createRecordStore(database: FirestoreLike, root: string): RecordStore {
|
|
178
|
+
const records = database.collection(root);
|
|
179
|
+
return {
|
|
180
|
+
async create(collection, data) {
|
|
181
|
+
const document = records.doc();
|
|
182
|
+
const now = new Date().toISOString();
|
|
183
|
+
const value = {id: document.id, collection, data, createdAt: now, updatedAt: now};
|
|
184
|
+
await document.set(value);
|
|
185
|
+
return value;
|
|
186
|
+
},
|
|
187
|
+
async list(collection) {
|
|
188
|
+
const snapshot = await records.where('collection', '==', collection).orderBy('createdAt', 'desc').limit(100).get();
|
|
189
|
+
return snapshot.docs.map((document) => document.data() ?? {id: document.id});
|
|
190
|
+
},
|
|
191
|
+
async get(id) {
|
|
192
|
+
const snapshot = await records.doc(id).get();
|
|
193
|
+
return snapshot.exists ? snapshot.data() ?? {id} : null;
|
|
194
|
+
},
|
|
195
|
+
async delete(id) {
|
|
196
|
+
const document = records.doc(id);
|
|
197
|
+
const snapshot = await document.get();
|
|
198
|
+
if (!snapshot.exists) return false;
|
|
199
|
+
await document.delete();
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function createKeyValueStore(database: FirestoreLike, root: string): KeyValueStore {
|
|
206
|
+
const entries = database.collection(root);
|
|
207
|
+
return {
|
|
208
|
+
async set(namespaceValue, keyValue, value) {
|
|
209
|
+
const locator = kvsLocator(namespaceValue, keyValue);
|
|
210
|
+
await kvsStorage(() => entries.doc(kvsDocumentId(locator.namespace, locator.key)).set({
|
|
211
|
+
namespace: locator.namespace,
|
|
212
|
+
key: locator.key,
|
|
213
|
+
value,
|
|
214
|
+
updatedAt: new Date().toISOString()
|
|
215
|
+
}));
|
|
216
|
+
},
|
|
217
|
+
async get(namespaceValue, keyValue) {
|
|
218
|
+
const locator = kvsLocator(namespaceValue, keyValue);
|
|
219
|
+
const snapshot = await kvsStorage(() => entries.doc(kvsDocumentId(locator.namespace, locator.key)).get());
|
|
220
|
+
if (!snapshot.exists) return null;
|
|
221
|
+
const value = snapshot.data()?.value;
|
|
222
|
+
if (typeof value !== 'string') throw Object.assign(new Error('KVS_STORAGE_FAILURE'), {code: 'KVS_STORAGE_FAILURE'});
|
|
223
|
+
return value;
|
|
224
|
+
},
|
|
225
|
+
async has(namespaceValue, keyValue) {
|
|
226
|
+
const locator = kvsLocator(namespaceValue, keyValue);
|
|
227
|
+
return (await kvsStorage(() => entries.doc(kvsDocumentId(locator.namespace, locator.key)).get())).exists;
|
|
228
|
+
},
|
|
229
|
+
async delete(namespaceValue, keyValue) {
|
|
230
|
+
const locator = kvsLocator(namespaceValue, keyValue);
|
|
231
|
+
const document = entries.doc(kvsDocumentId(locator.namespace, locator.key));
|
|
232
|
+
return kvsStorage(() => database.runTransaction(async (transaction) => {
|
|
233
|
+
const snapshot = await transaction.get(document);
|
|
234
|
+
if (!snapshot.exists) return false;
|
|
235
|
+
transaction.delete(document);
|
|
236
|
+
return true;
|
|
237
|
+
}));
|
|
238
|
+
},
|
|
239
|
+
async list(namespaceValue) {
|
|
240
|
+
const namespace = kvsLocator(namespaceValue, 'placeholder').namespace;
|
|
241
|
+
const snapshot = await kvsStorage(() => entries.where('namespace', '==', namespace).orderBy('key', 'asc').get());
|
|
242
|
+
return snapshot.docs.map((document) => {
|
|
243
|
+
const key = document.data()?.key;
|
|
244
|
+
if (typeof key !== 'string') throw Object.assign(new Error('KVS_STORAGE_FAILURE'), {code: 'KVS_STORAGE_FAILURE'});
|
|
245
|
+
return key;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function kvsDocumentId(namespace: string, key: string): string {
|
|
251
|
+
return createHash('sha256').update(JSON.stringify([namespace, key])).digest('hex');
|
|
252
|
+
}
|
|
253
|
+
function kvsLocator(namespaceValue: string, keyValue: string): {namespace: string; key: string} {
|
|
254
|
+
const namespace = namespaceValue.normalize('NFC');
|
|
255
|
+
const key = keyValue.normalize('NFC');
|
|
256
|
+
if (!/^[a-z][a-z0-9.-]{0,63}$/u.test(namespace)) throw Object.assign(new Error('KVS_NAMESPACE_INVALID'), {code: 'KVS_NAMESPACE_INVALID'});
|
|
257
|
+
if (key.length === 0 || key.length > 512 || key.includes('\\0') || key.split('/').some((part) => part === '.' || part === '..')) throw Object.assign(new Error('KVS_KEY_INVALID'), {code: 'KVS_KEY_INVALID'});
|
|
258
|
+
return {namespace, key};
|
|
259
|
+
}
|
|
260
|
+
async function kvsStorage<T>(operation: () => Promise<T>): Promise<T> {
|
|
261
|
+
try {return await operation();}
|
|
262
|
+
catch (error) {if (isKvsFault(error)) throw error; throw Object.assign(new Error('KVS_STORAGE_FAILURE'), {code: 'KVS_STORAGE_FAILURE'});}
|
|
263
|
+
}
|
|
264
|
+
function isKvsFault(error: unknown): error is Error & {code: string} {return error instanceof Error && 'code' in error && typeof error.code === 'string' && error.code.startsWith('KVS_')}
|
|
265
|
+
|
|
266
|
+
export function createObjectStore(bucket: BucketLike): BinaryObjectStore {
|
|
267
|
+
return {
|
|
268
|
+
async resolve(locator) {
|
|
269
|
+
try {return metadataRef(locator, (await bucket.file(storageKey(locator)).getMetadata())[0])}
|
|
270
|
+
catch (error) {if (isBinaryFault(error)) throw error; if (isNotFound(error)) return null; throw binaryFault('BINARY_STORAGE_FAILURE')}
|
|
271
|
+
},
|
|
272
|
+
async get(ref) {
|
|
273
|
+
try {
|
|
274
|
+
const key = storageKey(ref);
|
|
275
|
+
const metadata = (await bucket.file(key).getMetadata())[0];
|
|
276
|
+
const generation = metadataGeneration(metadata);
|
|
277
|
+
if (ref.revision !== undefined && generation !== ref.revision) return null;
|
|
278
|
+
const file = bucket.file(key, {generation});
|
|
279
|
+
const size = metadataSize(metadata);
|
|
280
|
+
const source: BinaryBodySource = {
|
|
281
|
+
chunks: file.createReadStream(),
|
|
282
|
+
...(size === undefined ? {} : {size})
|
|
283
|
+
};
|
|
284
|
+
return metadata.contentType === undefined ? source : {...source, contentType: metadata.contentType};
|
|
285
|
+
} catch (error) {if (isBinaryFault(error)) throw error; if (isNotFound(error)) return null; throw binaryFault('BINARY_STORAGE_FAILURE')}
|
|
286
|
+
},
|
|
287
|
+
async put(locator, source, metadata, maxBytes) {
|
|
288
|
+
const destination = bucket.file(storageKey(locator));
|
|
289
|
+
const staging = bucket.file('v1/.staging/' + crypto.randomUUID());
|
|
290
|
+
const hash = createHash('sha256');
|
|
291
|
+
const output = staging.createWriteStream({
|
|
292
|
+
resumable: false,
|
|
293
|
+
metadata: {
|
|
294
|
+
...(metadata.contentType === undefined ? {} : {contentType: metadata.contentType}),
|
|
295
|
+
metadata: {}
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
let size = 0;
|
|
299
|
+
let stagingGeneration: string | number | undefined;
|
|
300
|
+
try {
|
|
301
|
+
for await (const chunk of source.chunks) {
|
|
302
|
+
size += chunk.byteLength;
|
|
303
|
+
if (size > maxBytes) throw binaryFault('BINARY_TOO_LARGE');
|
|
304
|
+
hash.update(chunk);
|
|
305
|
+
if (!output.write(chunk)) await once(output, 'drain');
|
|
306
|
+
}
|
|
307
|
+
output.end();
|
|
308
|
+
await once(output, 'finish');
|
|
309
|
+
const integrity = 'sha256:' + hash.digest('hex');
|
|
310
|
+
if (metadata.size !== undefined && metadata.size !== size || metadata.integrity !== undefined && metadata.integrity !== integrity) {
|
|
311
|
+
throw binaryFault('BINARY_INTEGRITY_MISMATCH');
|
|
312
|
+
}
|
|
313
|
+
const initial = (await staging.getMetadata())[0];
|
|
314
|
+
stagingGeneration = initial.generation;
|
|
315
|
+
await staging.setMetadata({metadata: {...initial.metadata, twIntegrity: integrity}});
|
|
316
|
+
const [, response] = await staging.copy(destination);
|
|
317
|
+
const stored = copiedMetadata(response);
|
|
318
|
+
return {...metadataRef(locator, stored), integrity, size};
|
|
319
|
+
} catch (error) {
|
|
320
|
+
output.destroy();
|
|
321
|
+
if (isBinaryFault(error)) throw error;
|
|
322
|
+
throw binaryFault('BINARY_STORAGE_FAILURE');
|
|
323
|
+
} finally {
|
|
324
|
+
await staging.delete({
|
|
325
|
+
ignoreNotFound: true,
|
|
326
|
+
...(stagingGeneration === undefined ? {} : {ifGenerationMatch: stagingGeneration})
|
|
327
|
+
}).catch(() => undefined);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
async delete(target) {
|
|
331
|
+
const file = bucket.file(storageKey(target));
|
|
332
|
+
try {
|
|
333
|
+
await file.delete(
|
|
334
|
+
'revision' in target && target.revision !== undefined
|
|
335
|
+
? {ifGenerationMatch: target.revision}
|
|
336
|
+
: undefined
|
|
337
|
+
);
|
|
338
|
+
return true;
|
|
339
|
+
} catch (error) {if (isBinaryFault(error)) throw error; if (isNotFound(error) || isPreconditionFailed(error)) return false; throw binaryFault('BINARY_STORAGE_FAILURE')}
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function storageKey(locator: BinaryLocator): string {
|
|
344
|
+
if (!/^[a-z][a-z0-9.-]{0,63}$/u.test(locator.namespace) || locator.key.length > 512 || locator.key.includes('\\0') || locator.key.startsWith('/') || locator.key.includes('\\\\') || locator.key.split('/').some((part) => part.length === 0 || part === '.' || part === '..')) {
|
|
345
|
+
throw binaryFault('BINARY_INVALID_REF');
|
|
346
|
+
}
|
|
347
|
+
return 'v1/' + locator.namespace + '/' + locator.key;
|
|
348
|
+
}
|
|
349
|
+
function metadataRef(locator: BinaryLocator, metadata: StorageMetadata): BinaryRef {
|
|
350
|
+
const integrityValue = metadata.metadata?.twIntegrity;
|
|
351
|
+
const integrity = typeof integrityValue === 'string' ? integrityValue : undefined;
|
|
352
|
+
const revision = metadataGeneration(metadata);
|
|
353
|
+
const size = metadataSize(metadata);
|
|
354
|
+
return {
|
|
355
|
+
...locator,
|
|
356
|
+
...(size === undefined ? {} : {size}),
|
|
357
|
+
revision,
|
|
358
|
+
...(metadata.contentType === undefined ? {} : {contentType: metadata.contentType}),
|
|
359
|
+
...(integrity === undefined ? {} : {integrity})
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function metadataSize(metadata: StorageMetadata): number | undefined {
|
|
363
|
+
const size = metadata.size === undefined ? undefined : Number(metadata.size);
|
|
364
|
+
return size !== undefined && Number.isSafeInteger(size) && size >= 0 ? size : undefined;
|
|
365
|
+
}
|
|
366
|
+
function metadataGeneration(metadata: StorageMetadata): string {
|
|
367
|
+
if ((typeof metadata.generation !== 'string' && typeof metadata.generation !== 'number') || String(metadata.generation).length === 0) {
|
|
368
|
+
throw binaryFault('BINARY_STORAGE_FAILURE');
|
|
369
|
+
}
|
|
370
|
+
return String(metadata.generation);
|
|
371
|
+
}
|
|
372
|
+
function copiedMetadata(response: unknown): StorageMetadata {
|
|
373
|
+
if (typeof response !== 'object' || response === null || !('resource' in response)) {
|
|
374
|
+
throw binaryFault('BINARY_STORAGE_FAILURE');
|
|
375
|
+
}
|
|
376
|
+
const resource = response.resource;
|
|
377
|
+
if (typeof resource !== 'object' || resource === null || Array.isArray(resource)) {
|
|
378
|
+
throw binaryFault('BINARY_STORAGE_FAILURE');
|
|
379
|
+
}
|
|
380
|
+
const metadata = resource as StorageMetadata;
|
|
381
|
+
metadataGeneration(metadata);
|
|
382
|
+
return metadata;
|
|
383
|
+
}
|
|
384
|
+
function binaryFault(code: string): Error & {code: string} {return Object.assign(new Error(code), {code})}
|
|
385
|
+
function isBinaryFault(error: unknown): error is Error & {code: string} {return error instanceof Error && 'code' in error && typeof error.code === 'string' && error.code.startsWith('BINARY_')}
|
|
386
|
+
function isNotFound(error: unknown): boolean {return typeof error === 'object' && error !== null && 'code' in error && (error.code === 404 || error.code === '404')}
|
|
387
|
+
function isPreconditionFailed(error: unknown): boolean {return typeof error === 'object' && error !== null && 'code' in error && (error.code === 412 || error.code === '412')}
|
|
388
|
+
`;
|
|
389
|
+
}
|
|
390
|
+
function functionsPackage(ir) {
|
|
391
|
+
return `${JSON.stringify({
|
|
392
|
+
name: `${ir.name.toLowerCase().replace(/[^a-z0-9._-]+/gu, '-')}-functions`,
|
|
393
|
+
private: true,
|
|
394
|
+
type: 'module',
|
|
395
|
+
main: 'lib/index.js',
|
|
396
|
+
engines: { node: '22' },
|
|
397
|
+
scripts: {
|
|
398
|
+
build: 'tsc',
|
|
399
|
+
typecheck: 'tsc --noEmit',
|
|
400
|
+
serve: 'npm run build && firebase emulators:start --config ../firebase.json --only functions,firestore,storage',
|
|
401
|
+
deploy: 'firebase deploy --config ../firebase.json --only functions,firestore,storage'
|
|
402
|
+
},
|
|
403
|
+
dependencies: {
|
|
404
|
+
'@hono/node-server': '^2.1.1',
|
|
405
|
+
'firebase-admin': '^14.4.0',
|
|
406
|
+
'firebase-functions': '^7.4.0',
|
|
407
|
+
hono: '^4.13.8'
|
|
408
|
+
},
|
|
409
|
+
devDependencies: { '@types/node': '^24.13.3', 'firebase-tools': '^15.30.2', typescript: '^5.9.3' }
|
|
410
|
+
}, null, 2)}\n`;
|
|
411
|
+
}
|
|
412
|
+
function functionsTsconfig() {
|
|
413
|
+
return `${JSON.stringify({
|
|
414
|
+
compilerOptions: {
|
|
415
|
+
target: 'ES2022',
|
|
416
|
+
module: 'NodeNext',
|
|
417
|
+
moduleResolution: 'NodeNext',
|
|
418
|
+
lib: ['ES2022', 'DOM'],
|
|
419
|
+
types: ['node'],
|
|
420
|
+
rootDir: 'src',
|
|
421
|
+
outDir: 'lib',
|
|
422
|
+
strict: true,
|
|
423
|
+
skipLibCheck: true
|
|
424
|
+
},
|
|
425
|
+
include: ['src/**/*.ts']
|
|
426
|
+
}, null, 2)}\n`;
|
|
427
|
+
}
|
|
428
|
+
function firebaseJson() {
|
|
429
|
+
return `${JSON.stringify({
|
|
430
|
+
functions: { source: 'functions', predeploy: ['npm --prefix functions run build'] },
|
|
431
|
+
firestore: { rules: 'firestore.rules', indexes: 'firestore.indexes.json' },
|
|
432
|
+
storage: { rules: 'storage.rules' },
|
|
433
|
+
emulators: { functions: { port: 5001 }, firestore: { port: 8080 }, storage: { port: 9199 } }
|
|
434
|
+
}, null, 2)}\n`;
|
|
435
|
+
}
|
|
436
|
+
function firebaserc() {
|
|
437
|
+
return `${JSON.stringify({ projects: { default: 'replace-me' } }, null, 2)}\n`;
|
|
438
|
+
}
|
|
439
|
+
function firestoreIndexes(plan) {
|
|
440
|
+
const collection = plan.bindings.recordCollection;
|
|
441
|
+
const keyValueCollection = plan.bindings.keyValueCollection;
|
|
442
|
+
const indexes = [
|
|
443
|
+
...(collection === undefined
|
|
444
|
+
? []
|
|
445
|
+
: [
|
|
446
|
+
{
|
|
447
|
+
collectionGroup: collection,
|
|
448
|
+
queryScope: 'COLLECTION',
|
|
449
|
+
fields: [
|
|
450
|
+
{ fieldPath: 'collection', order: 'ASCENDING' },
|
|
451
|
+
{ fieldPath: 'createdAt', order: 'DESCENDING' }
|
|
452
|
+
]
|
|
453
|
+
}
|
|
454
|
+
]),
|
|
455
|
+
...(keyValueCollection === undefined
|
|
456
|
+
? []
|
|
457
|
+
: [
|
|
458
|
+
{
|
|
459
|
+
collectionGroup: keyValueCollection,
|
|
460
|
+
queryScope: 'COLLECTION',
|
|
461
|
+
fields: [
|
|
462
|
+
{ fieldPath: 'namespace', order: 'ASCENDING' },
|
|
463
|
+
{ fieldPath: 'key', order: 'ASCENDING' }
|
|
464
|
+
]
|
|
465
|
+
}
|
|
466
|
+
])
|
|
467
|
+
];
|
|
468
|
+
return `${JSON.stringify({ indexes, fieldOverrides: [] }, null, 2)}\n`;
|
|
469
|
+
}
|
|
470
|
+
function denyAllRules(service) {
|
|
471
|
+
if (service === 'cloud.firestore') {
|
|
472
|
+
return `rules_version = '2';\nservice cloud.firestore {\n match /databases/{database}/documents {\n match /{document=**} {\n allow read, write: if false;\n }\n }\n}\n`;
|
|
473
|
+
}
|
|
474
|
+
return `rules_version = '2';\nservice firebase.storage {\n match /b/{bucket}/o {\n match /{object=**} {\n allow read, write: if false;\n }\n }\n}\n`;
|
|
475
|
+
}
|
|
476
|
+
function generatedReadme(plan) {
|
|
477
|
+
const bucketEnvironment = plan.bindings.objectBucketEnv;
|
|
478
|
+
return `# Generated Firebase Functions application
|
|
479
|
+
|
|
480
|
+
Run \`npm --prefix functions install\`, copy \`.firebaserc.example\` to \`.firebaserc\`, and replace \`replace-me\` with the Firebase project alias. When using a non-default Storage bucket, configure the bucket name through the \`${bucketEnvironment ?? 'ASSET_BUCKET'}\` environment variable; never commit credentials.
|
|
481
|
+
|
|
482
|
+
The generated HTTP function uses the Admin SDK and IAM. Firestore and Storage client Rules deny all access by default and do not authorize the Admin SDK. Firestore stores KVS text entries with hashed document IDs; key listing is lexicographically ordered. Binary uploads are validated under \`v1/.staging/\` before being copied to their destination; cleanup is best effort, so configure a lifecycle rule for abandoned staging objects. Use \`npm --prefix functions run serve\` for the Emulator Suite boundary and \`npm --prefix functions run deploy\` only after reviewing billing and IAM.
|
|
483
|
+
|
|
484
|
+
## Rollback and cleanup
|
|
485
|
+
|
|
486
|
+
Roll back or delete the generated HTTP function before changing data resources. The generator never deletes Firestore documents or Storage objects. Export required data and inspect IAM, bucket, Firestore, and dependent functions before manual cleanup.
|
|
487
|
+
`;
|
|
488
|
+
}
|
|
489
|
+
//# sourceMappingURL=firebase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../../../src/compiler/adapters/firebase.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,oBAAoB,EAAC,MAAM,6BAA6B,CAAC;AASjE,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACvD,EAAE,EAAE,oBAAoB;IACxB,OAAO,EAAE,OAAO;IAChB,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;QACnB,IAAI,EAAE,CAAC,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,iCAAiC,EAAE,gBAAgB,CAAC;QAChH,cAAc,EAAE,QAAU;KAC3B,CAAC;IACF,IAAI,CAAC,EAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAC;QAC7B,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,CAC1C,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,wBAAwB,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CACrF,CAAC;QACF,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,oBAAoB,CAAC,WAAW,E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names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAC,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BinaryContentDispositionV2, BinaryLocatorV2, BinaryMetadataV2 } from '../ir-v2/types.js';
|
|
2
|
+
export declare function validateBinaryLocator(locator: BinaryLocatorV2): BinaryLocatorV2;
|
|
3
|
+
export declare function validateBinaryMetadata(metadata: BinaryMetadataV2): BinaryMetadataV2;
|
|
4
|
+
export declare function encodeContentDisposition(disposition: BinaryContentDispositionV2): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { binaryError } from './error.js';
|
|
2
|
+
import { isNamedDataNamespace } from '../../named-data-namespace.js';
|
|
3
|
+
export function validateBinaryLocator(locator) {
|
|
4
|
+
if (!isNamedDataNamespace(locator.namespace)) {
|
|
5
|
+
binaryError('BINARY_INVALID_REF', 'Binary namespace is invalid.');
|
|
6
|
+
}
|
|
7
|
+
if (locator.key.length < 1 ||
|
|
8
|
+
locator.key.length > 512 ||
|
|
9
|
+
locator.key.includes('\0') ||
|
|
10
|
+
locator.key.includes('\\') ||
|
|
11
|
+
locator.key.startsWith('/') ||
|
|
12
|
+
locator.key.split('/').some((segment) => segment.length === 0 || segment === '.' || segment === '..')) {
|
|
13
|
+
binaryError('BINARY_INVALID_REF', 'Binary key is invalid.');
|
|
14
|
+
}
|
|
15
|
+
return { namespace: locator.namespace, key: locator.key };
|
|
16
|
+
}
|
|
17
|
+
export function validateBinaryMetadata(metadata) {
|
|
18
|
+
if (metadata.contentType !== undefined &&
|
|
19
|
+
(metadata.contentType.length > 255 ||
|
|
20
|
+
!/^[^\s/;]+\/[^\s;]+(?:\s*;.*)?$/u.test(metadata.contentType) ||
|
|
21
|
+
/[\r\n]/u.test(metadata.contentType))) {
|
|
22
|
+
binaryError('BINARY_INVALID_REF', 'Binary content type is invalid.');
|
|
23
|
+
}
|
|
24
|
+
if (metadata.size !== undefined && (!Number.isSafeInteger(metadata.size) || metadata.size < 0)) {
|
|
25
|
+
binaryError('BINARY_INVALID_REF', 'Binary size is invalid.');
|
|
26
|
+
}
|
|
27
|
+
if (metadata.integrity !== undefined && !/^sha256:[0-9a-f]{64}$/u.test(metadata.integrity)) {
|
|
28
|
+
binaryError('BINARY_INVALID_REF', 'Binary integrity is invalid.');
|
|
29
|
+
}
|
|
30
|
+
if (metadata.revision !== undefined && (metadata.revision.length < 1 || metadata.revision.length > 256)) {
|
|
31
|
+
binaryError('BINARY_INVALID_REF', 'Binary revision is invalid.');
|
|
32
|
+
}
|
|
33
|
+
return { ...metadata };
|
|
34
|
+
}
|
|
35
|
+
export function encodeContentDisposition(disposition) {
|
|
36
|
+
if (disposition.kind === 'inline')
|
|
37
|
+
return 'inline';
|
|
38
|
+
if (disposition.filename.length < 1 ||
|
|
39
|
+
disposition.filename.length > 255 ||
|
|
40
|
+
/[\r\n\0]/u.test(disposition.filename)) {
|
|
41
|
+
binaryError('BINARY_INVALID_REF', 'Binary response filename is invalid.');
|
|
42
|
+
}
|
|
43
|
+
return `attachment; filename*=UTF-8''${encodeURIComponent(disposition.filename).replace(/['()*]/gu, (value) => `%${value.codePointAt(0).toString(16).toUpperCase()}`)}`;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/compiler/binary/codec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AAEnE,MAAM,UAAU,qBAAqB,CAAC,OAAwB;IAC5D,IACE,CAAC,oBAAoB,CAAC,OAAO,CAAC,SAAS,CAAC,EACxC,CAAC;QACD,WAAW,CAAC,oBAAoB,EAAE,8BAA8B,CAAC,CAAC;IACpE,CAAC;IACD,I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"];
|
|
2
|
+
export type BinaryRuntimeErrorCode = (typeof BINARY_RUNTIME_ERROR_CODES)[number];
|
|
3
|
+
export declare function binaryError(code: BinaryRuntimeErrorCode, message: string): never;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IrRuntimeError } from '../runtime/error.js';
|
|
2
|
+
export const BINARY_RUNTIME_ERROR_CODES = [
|
|
3
|
+
'BINARY_INVALID_REF',
|
|
4
|
+
'BINARY_NOT_FOUND',
|
|
5
|
+
'BINARY_TOO_LARGE',
|
|
6
|
+
'BINARY_INTEGRITY_MISMATCH',
|
|
7
|
+
'BINARY_BODY_CONSUMED',
|
|
8
|
+
'BINARY_STORAGE_FAILURE'
|
|
9
|
+
];
|
|
10
|
+
const BINARY_STATUS = {
|
|
11
|
+
BINARY_INVALID_REF: 422,
|
|
12
|
+
BINARY_NOT_FOUND: 404,
|
|
13
|
+
BINARY_TOO_LARGE: 413,
|
|
14
|
+
BINARY_INTEGRITY_MISMATCH: 502,
|
|
15
|
+
BINARY_BODY_CONSUMED: 500,
|
|
16
|
+
BINARY_STORAGE_FAILURE: 502
|
|
17
|
+
};
|
|
18
|
+
export function binaryError(code, message) {
|
|
19
|
+
throw new IrRuntimeError(code, message, BINARY_STATUS[code]);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/compiler/binary/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,oBAAoB;IACpB,kBAAkB;IAClB,kBAAkB;IAClB,2BAA2B;IAC3B,sBAAsB;IACtB,wBAAwB;CAChB,CAAC;AAIX,MAAM,aAAa,GAA2C;IAC5D,kBAAkB,EAAE,GAAG;IACvB,gBAAgB,EAAE,GAAG;IACrB,gBAAgB,EAAE,GAAG;IACrB,yBAAyB,EAAE,GAAG;IAC9B,oBAAoB,EAAE,GAAG;IACzB,sBAAsB,EAAE,GAAG;CAC5B,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,IAA4B,EAAE,OAAe;IACvE,MAAM,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compiler/binary/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BinaryLocatorV2, BinaryMetadataV2, BinaryRefDescriptorV2 } from '../ir-v2/types.js';
|
|
2
|
+
import { type BinaryBodySource, type BinaryObjectStore } from './types.js';
|
|
3
|
+
export declare class BinaryBodyHandle {
|
|
4
|
+
private readonly source;
|
|
5
|
+
private consumed;
|
|
6
|
+
constructor(source: BinaryBodySource);
|
|
7
|
+
take(): BinaryBodySource;
|
|
8
|
+
}
|
|
9
|
+
export declare function effectiveBinaryLimit(operationLimit: number, compilerLimit?: number, targetLimit?: number): number;
|
|
10
|
+
export declare function collectBinaryBody(source: BinaryBodySource, maxBytes: number): Promise<Uint8Array>;
|
|
11
|
+
export declare class InMemoryBinaryObjectStore implements BinaryObjectStore {
|
|
12
|
+
private readonly objects;
|
|
13
|
+
private revision;
|
|
14
|
+
resolve(locator: BinaryLocatorV2): Promise<BinaryRefDescriptorV2 | null>;
|
|
15
|
+
get(ref: BinaryRefDescriptorV2): Promise<BinaryBodySource | null>;
|
|
16
|
+
put(locator: BinaryLocatorV2, source: BinaryBodySource, metadata: BinaryMetadataV2, maxBytes: number): Promise<BinaryRefDescriptorV2>;
|
|
17
|
+
delete(target: BinaryLocatorV2 | BinaryRefDescriptorV2): Promise<boolean>;
|
|
18
|
+
}
|