houdini 2.0.0-next.9 → 2.0.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/build/adapter/index.d.ts +2 -2
- package/build/adapter/index.js +6 -0
- package/build/cmd/generate.d.ts +5 -0
- package/build/cmd/generate.js +77 -0
- package/build/cmd/index.js +32 -0
- package/build/cmd/init.js +565 -0
- package/build/cmd/pullSchema.js +26 -0
- package/build/lib/ast.js +71 -0
- package/build/lib/codegen.d.ts +57 -0
- package/build/lib/codegen.js +627 -0
- package/build/lib/config.d.ts +240 -177
- package/build/lib/config.js +143 -0
- package/build/lib/constants.js +14 -0
- package/build/lib/database.d.ts +7 -0
- package/build/lib/database.js +624 -0
- package/build/lib/db.d.ts +13 -0
- package/build/lib/db.js +135 -0
- package/build/lib/deepMerge.js +23 -0
- package/build/lib/error.d.ts +16 -0
- package/build/lib/error.js +115 -0
- package/build/lib/fs.d.ts +9 -11
- package/build/lib/fs.js +245 -0
- package/build/lib/graphql.d.ts +5 -32
- package/build/lib/graphql.js +36 -0
- package/build/lib/imports.d.ts +29 -14
- package/build/lib/imports.js +66 -0
- package/build/lib/index.d.ts +17 -24
- package/build/lib/index.js +21 -0
- package/build/lib/logger.d.ts +12 -0
- package/build/lib/logger.js +45 -0
- package/build/lib/parse.d.ts +2 -3
- package/build/lib/parse.js +33 -0
- package/build/lib/path.d.ts +0 -1
- package/build/lib/path.js +44 -0
- package/build/lib/pipeline.d.ts +1 -1
- package/build/lib/pipeline.js +8 -0
- package/build/lib/plugins.d.ts +4 -0
- package/build/lib/plugins.js +88 -0
- package/build/lib/project.d.ts +19 -0
- package/build/lib/project.js +296 -0
- package/build/lib/schema.d.ts +1 -0
- package/build/lib/schema.js +61 -0
- package/build/lib/sleep.d.ts +1 -0
- package/build/lib/sleep.js +8 -0
- package/build/lib/types.d.ts +92 -303
- package/build/lib/types.js +37 -0
- package/build/lib/walk.d.ts +11 -6
- package/build/lib/walk.js +138 -0
- package/build/node/index.d.ts +44 -0
- package/build/node/index.js +402 -0
- package/build/oauth/index.d.ts +41 -0
- package/build/oauth/index.js +108 -0
- package/build/package.json +212 -0
- package/build/router/auth-token.d.ts +29 -0
- package/build/router/auth-token.js +168 -0
- package/build/{lib/router → router}/conventions.d.ts +10 -1
- package/build/router/conventions.js +165 -0
- package/build/{runtime-esm/router → router}/cookies.js +21 -21
- package/build/{runtime-esm/router → router}/jwt.js +8 -6
- package/build/{lib/router → router}/manifest.d.ts +2 -2
- package/build/router/manifest.js +279 -0
- package/build/{runtime/router → router}/match.d.ts +10 -10
- package/build/router/match.js +219 -0
- package/build/router/server.d.ts +57 -0
- package/build/router/server.js +500 -0
- package/build/{runtime/router → router}/session.d.ts +8 -3
- package/build/router/session.js +338 -0
- package/build/router/types.d.ts +44 -0
- package/build/runtime/cache/benchmarks/cache.bench.d.ts +1 -0
- package/build/runtime/cache/benchmarks/cache.bench.js +943 -0
- package/build/runtime/cache/gc.d.ts +2 -1
- package/build/{runtime-esm → runtime}/cache/gc.js +4 -1
- package/build/runtime/cache/index.d.ts +173 -3
- package/build/{runtime-esm/cache/cache.js → runtime/cache/index.js} +197 -70
- package/build/runtime/cache/lists.d.ts +9 -4
- package/build/{runtime-esm → runtime}/cache/lists.js +116 -27
- package/build/runtime/cache/staleManager.d.ts +2 -1
- package/build/{runtime-esm → runtime}/cache/staleManager.js +6 -2
- package/build/runtime/cache/storage.d.ts +5 -2
- package/build/{runtime-esm → runtime}/cache/storage.js +126 -54
- package/build/{runtime-esm → runtime}/cache/stuff.js +4 -3
- package/build/runtime/cache/subscription.d.ts +23 -9
- package/build/{runtime-esm → runtime}/cache/subscription.js +103 -65
- package/build/runtime/{client/index.d.ts → client.d.ts} +15 -22
- package/build/runtime/client.js +86 -0
- package/build/runtime/coerce.d.ts +4 -0
- package/build/runtime/coerce.js +31 -0
- package/build/runtime/config.d.ts +20 -0
- package/build/runtime/config.js +88 -0
- package/build/runtime/{lib/constants.d.ts → constants.d.ts} +1 -1
- package/build/runtime/{client/documentStore.d.ts → documentStore.d.ts} +18 -11
- package/build/{runtime-esm/client → runtime}/documentStore.js +53 -56
- package/build/runtime/endpoint.d.ts +14 -0
- package/build/runtime/endpoint.js +29 -0
- package/build/{runtime-cjs/lib → runtime}/flatten.d.ts +1 -1
- package/build/runtime/formData.d.ts +24 -0
- package/build/runtime/formData.js +93 -0
- package/build/runtime/index.d.ts +16 -8
- package/build/runtime/index.js +54 -0
- package/build/{runtime-cjs/lib → runtime}/key.d.ts +1 -1
- package/build/{runtime-esm/lib → runtime}/key.js +4 -4
- package/build/{runtime-esm/lib → runtime}/log.js +3 -3
- package/build/runtime/multipart.d.ts +8 -0
- package/build/runtime/multipart.js +49 -0
- package/build/{runtime-cjs/lib → runtime}/pageInfo.d.ts +3 -3
- package/build/{runtime-esm/lib → runtime}/pageInfo.js +2 -2
- package/build/{runtime-cjs/lib → runtime}/pagination.d.ts +12 -8
- package/build/{runtime-esm/lib → runtime}/pagination.js +157 -21
- package/build/{runtime-cjs/lib → runtime}/scalars.d.ts +6 -6
- package/build/{runtime-esm/lib → runtime}/scalars.js +10 -43
- package/build/{runtime-cjs/lib → runtime}/selection.d.ts +1 -1
- package/build/{runtime-esm/lib → runtime}/selection.js +17 -2
- package/build/runtime/{lib/store.d.ts → store.d.ts} +1 -1
- package/build/{runtime-esm/lib → runtime}/store.js +2 -3
- package/build/runtime/{lib/types.d.ts → types.d.ts} +107 -102
- package/build/{runtime-esm/lib → runtime}/types.js +37 -15
- package/build/test/index.d.ts +6 -25
- package/build/test/index.js +329 -0
- package/build/test/package.json +1 -0
- package/build/vite/hmr.d.ts +26 -3
- package/build/vite/hmr.js +433 -0
- package/build/vite/houdini.d.ts +4 -10
- package/build/vite/houdini.js +144 -0
- package/build/vite/index.d.ts +13 -7
- package/build/vite/index.js +106 -0
- package/build/vite/package.json +1 -0
- package/build/vite/schema.d.ts +5 -3
- package/build/vite/schema.js +193 -0
- package/package.json +148 -57
- package/build/adapter-cjs/index.js +0 -33
- package/build/adapter-cjs/package.json +0 -1
- package/build/adapter-esm/index.js +0 -9
- package/build/cmd-cjs/index.js +0 -89299
- package/build/cmd-cjs/package.json +0 -1
- package/build/cmd-esm/index.js +0 -89303
- package/build/codegen/generators/artifacts/fieldKey.d.ts +0 -3
- package/build/codegen/generators/artifacts/index.d.ts +0 -17
- package/build/codegen/generators/artifacts/indexFile.d.ts +0 -2
- package/build/codegen/generators/artifacts/inputs.d.ts +0 -4
- package/build/codegen/generators/artifacts/operations.d.ts +0 -11
- package/build/codegen/generators/artifacts/selection.d.ts +0 -20
- package/build/codegen/generators/artifacts/utils.d.ts +0 -8
- package/build/codegen/generators/comments/jsdoc.d.ts +0 -2
- package/build/codegen/generators/definitions/enums.d.ts +0 -2
- package/build/codegen/generators/definitions/index.d.ts +0 -2
- package/build/codegen/generators/index.d.ts +0 -6
- package/build/codegen/generators/indexFile/index.d.ts +0 -2
- package/build/codegen/generators/persistedQueries/index.d.ts +0 -2
- package/build/codegen/generators/runtime/graphqlFunction.d.ts +0 -2
- package/build/codegen/generators/runtime/index.d.ts +0 -3
- package/build/codegen/generators/runtime/injectPlugins.d.ts +0 -7
- package/build/codegen/generators/runtime/pluginIndex.d.ts +0 -5
- package/build/codegen/generators/runtime/pluginRuntime.d.ts +0 -15
- package/build/codegen/generators/runtime/runtimeConfig.d.ts +0 -7
- package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +0 -4
- package/build/codegen/generators/typescript/documentTypes.d.ts +0 -2
- package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +0 -2
- package/build/codegen/generators/typescript/index.d.ts +0 -2
- package/build/codegen/generators/typescript/inlineType.d.ts +0 -29
- package/build/codegen/generators/typescript/loadingState.d.ts +0 -8
- package/build/codegen/index.d.ts +0 -8
- package/build/codegen/transforms/addFields.d.ts +0 -2
- package/build/codegen/transforms/collectDefinitions.d.ts +0 -9
- package/build/codegen/transforms/componentFields.d.ts +0 -8
- package/build/codegen/transforms/fragmentVariables.d.ts +0 -17
- package/build/codegen/transforms/index.d.ts +0 -9
- package/build/codegen/transforms/list.d.ts +0 -9
- package/build/codegen/transforms/paginate.d.ts +0 -4
- package/build/codegen/transforms/runtimeScalars.d.ts +0 -2
- package/build/codegen/transforms/schema.d.ts +0 -2
- package/build/codegen/transforms/typename.d.ts +0 -2
- package/build/codegen/utils/commonjs.d.ts +0 -5
- package/build/codegen/utils/flattenSelections.d.ts +0 -11
- package/build/codegen/utils/index.d.ts +0 -4
- package/build/codegen/utils/moduleExport.d.ts +0 -4
- package/build/codegen/utils/murmur.d.ts +0 -9
- package/build/codegen/utils/objectIdentificationSelection.d.ts +0 -3
- package/build/codegen/utils/stripLoc.d.ts +0 -3
- package/build/codegen/validators/componentFields.d.ts +0 -2
- package/build/codegen/validators/index.d.ts +0 -5
- package/build/codegen/validators/noIDAlias.d.ts +0 -2
- package/build/codegen/validators/plugins.d.ts +0 -3
- package/build/codegen/validators/typeCheck.d.ts +0 -5
- package/build/codegen/validators/uniqueNames.d.ts +0 -2
- package/build/codegen-cjs/index.js +0 -74656
- package/build/codegen-cjs/package.json +0 -1
- package/build/codegen-esm/index.js +0 -74655
- package/build/lib/cleanupFiles.d.ts +0 -1
- package/build/lib/detectTools.d.ts +0 -16
- package/build/lib/introspection.d.ts +0 -3
- package/build/lib/plugin.d.ts +0 -2
- package/build/lib/router/index.d.ts +0 -9
- package/build/lib/router/server.d.ts +0 -7
- package/build/lib/router/types.d.ts +0 -23
- package/build/lib/typescript.d.ts +0 -20
- package/build/lib/watchAndRun.d.ts +0 -61
- package/build/lib-cjs/index.js +0 -79739
- package/build/lib-cjs/package.json +0 -1
- package/build/lib-esm/index.js +0 -79648
- package/build/runtime/cache/cache.d.ts +0 -169
- package/build/runtime/client/plugins/cache.d.ts +0 -9
- package/build/runtime/client/plugins/fetch.d.ts +0 -38
- package/build/runtime/client/plugins/fetchParams.d.ts +0 -9
- package/build/runtime/client/plugins/fragment.d.ts +0 -2
- package/build/runtime/client/plugins/index.d.ts +0 -9
- package/build/runtime/client/plugins/injectedPlugins.d.ts +0 -4
- package/build/runtime/client/plugins/mutation.d.ts +0 -2
- package/build/runtime/client/plugins/optimisticKeys.d.ts +0 -7
- package/build/runtime/client/plugins/query.d.ts +0 -2
- package/build/runtime/client/plugins/subscription.d.ts +0 -20
- package/build/runtime/client/plugins/test.d.ts +0 -15
- package/build/runtime/client/plugins/throwOnError.d.ts +0 -8
- package/build/runtime/client/utils/documentPlugins.d.ts +0 -3
- package/build/runtime/client/utils/index.d.ts +0 -1
- package/build/runtime/generated.d.ts +0 -5
- package/build/runtime/imports/config.d.ts +0 -3
- package/build/runtime/imports/pluginConfig.d.ts +0 -3
- package/build/runtime/lib/config.d.ts +0 -216
- package/build/runtime/lib/deepEquals.d.ts +0 -1
- package/build/runtime/lib/flatten.d.ts +0 -2
- package/build/runtime/lib/index.d.ts +0 -10
- package/build/runtime/lib/key.d.ts +0 -6
- package/build/runtime/lib/log.d.ts +0 -6
- package/build/runtime/lib/lru.d.ts +0 -52
- package/build/runtime/lib/pageInfo.d.ts +0 -7
- package/build/runtime/lib/pagination.d.ts +0 -27
- package/build/runtime/lib/scalars.d.ts +0 -14
- package/build/runtime/lib/selection.d.ts +0 -2
- package/build/runtime/public/cache.d.ts +0 -42
- package/build/runtime/public/index.d.ts +0 -1
- package/build/runtime/public/list.d.ts +0 -18
- package/build/runtime/public/record.d.ts +0 -40
- package/build/runtime/public/tests/test.d.ts +0 -156
- package/build/runtime/public/types.d.ts +0 -62
- package/build/runtime/router/cookies.d.ts +0 -41
- package/build/runtime/router/jwt.d.ts +0 -117
- package/build/runtime/router/server.d.ts +0 -24
- package/build/runtime/router/types.d.ts +0 -26
- package/build/runtime/server/index.d.ts +0 -17
- package/build/runtime-cjs/cache/cache.d.ts +0 -169
- package/build/runtime-cjs/cache/cache.js +0 -1077
- package/build/runtime-cjs/cache/constants.d.ts +0 -1
- package/build/runtime-cjs/cache/constants.js +0 -28
- package/build/runtime-cjs/cache/gc.d.ts +0 -10
- package/build/runtime-cjs/cache/gc.js +0 -74
- package/build/runtime-cjs/cache/index.d.ts +0 -3
- package/build/runtime-cjs/cache/index.js +0 -25
- package/build/runtime-cjs/cache/lists.d.ts +0 -89
- package/build/runtime-cjs/cache/lists.js +0 -467
- package/build/runtime-cjs/cache/staleManager.d.ts +0 -31
- package/build/runtime-cjs/cache/staleManager.js +0 -123
- package/build/runtime-cjs/cache/storage.d.ts +0 -110
- package/build/runtime-cjs/cache/storage.js +0 -451
- package/build/runtime-cjs/cache/stuff.d.ts +0 -2
- package/build/runtime-cjs/cache/stuff.js +0 -56
- package/build/runtime-cjs/cache/subscription.d.ts +0 -52
- package/build/runtime-cjs/cache/subscription.js +0 -349
- package/build/runtime-cjs/client/documentStore.d.ts +0 -107
- package/build/runtime-cjs/client/documentStore.js +0 -487
- package/build/runtime-cjs/client/index.d.ts +0 -50
- package/build/runtime-cjs/client/index.js +0 -162
- package/build/runtime-cjs/client/plugins/cache.d.ts +0 -9
- package/build/runtime-cjs/client/plugins/cache.js +0 -138
- package/build/runtime-cjs/client/plugins/fetch.d.ts +0 -38
- package/build/runtime-cjs/client/plugins/fetch.js +0 -210
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +0 -9
- package/build/runtime-cjs/client/plugins/fetchParams.js +0 -47
- package/build/runtime-cjs/client/plugins/fragment.d.ts +0 -2
- package/build/runtime-cjs/client/plugins/fragment.js +0 -77
- package/build/runtime-cjs/client/plugins/index.d.ts +0 -9
- package/build/runtime-cjs/client/plugins/index.js +0 -45
- package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +0 -4
- package/build/runtime-cjs/client/plugins/injectedPlugins.js +0 -25
- package/build/runtime-cjs/client/plugins/mutation.d.ts +0 -2
- package/build/runtime-cjs/client/plugins/mutation.js +0 -89
- package/build/runtime-cjs/client/plugins/optimisticKeys.d.ts +0 -7
- package/build/runtime-cjs/client/plugins/optimisticKeys.js +0 -324
- package/build/runtime-cjs/client/plugins/query.d.ts +0 -2
- package/build/runtime-cjs/client/plugins/query.js +0 -93
- package/build/runtime-cjs/client/plugins/subscription.d.ts +0 -20
- package/build/runtime-cjs/client/plugins/subscription.js +0 -114
- package/build/runtime-cjs/client/plugins/test.d.ts +0 -15
- package/build/runtime-cjs/client/plugins/test.js +0 -118
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +0 -8
- package/build/runtime-cjs/client/plugins/throwOnError.js +0 -47
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +0 -3
- package/build/runtime-cjs/client/utils/documentPlugins.js +0 -57
- package/build/runtime-cjs/client/utils/index.d.ts +0 -1
- package/build/runtime-cjs/client/utils/index.js +0 -22
- package/build/runtime-cjs/generated.d.ts +0 -5
- package/build/runtime-cjs/generated.js +0 -16
- package/build/runtime-cjs/imports/config.d.ts +0 -3
- package/build/runtime-cjs/imports/config.js +0 -24
- package/build/runtime-cjs/imports/pluginConfig.d.ts +0 -3
- package/build/runtime-cjs/imports/pluginConfig.js +0 -25
- package/build/runtime-cjs/index.d.ts +0 -8
- package/build/runtime-cjs/index.js +0 -61
- package/build/runtime-cjs/lib/config.d.ts +0 -216
- package/build/runtime-cjs/lib/config.js +0 -110
- package/build/runtime-cjs/lib/constants.d.ts +0 -6
- package/build/runtime-cjs/lib/constants.js +0 -38
- package/build/runtime-cjs/lib/deepEquals.js +0 -52
- package/build/runtime-cjs/lib/flatten.js +0 -41
- package/build/runtime-cjs/lib/index.d.ts +0 -10
- package/build/runtime-cjs/lib/index.js +0 -40
- package/build/runtime-cjs/lib/key.js +0 -41
- package/build/runtime-cjs/lib/log.js +0 -72
- package/build/runtime-cjs/lib/lru.js +0 -73
- package/build/runtime-cjs/lib/pageInfo.js +0 -79
- package/build/runtime-cjs/lib/pagination.js +0 -240
- package/build/runtime-cjs/lib/scalars.js +0 -147
- package/build/runtime-cjs/lib/selection.js +0 -66
- package/build/runtime-cjs/lib/store.d.ts +0 -19
- package/build/runtime-cjs/lib/store.js +0 -81
- package/build/runtime-cjs/lib/types.d.ts +0 -417
- package/build/runtime-cjs/lib/types.js +0 -104
- package/build/runtime-cjs/package.json +0 -1
- package/build/runtime-cjs/public/cache.d.ts +0 -42
- package/build/runtime-cjs/public/cache.js +0 -98
- package/build/runtime-cjs/public/index.d.ts +0 -1
- package/build/runtime-cjs/public/index.js +0 -28
- package/build/runtime-cjs/public/list.d.ts +0 -18
- package/build/runtime-cjs/public/list.js +0 -151
- package/build/runtime-cjs/public/record.d.ts +0 -40
- package/build/runtime-cjs/public/record.js +0 -94
- package/build/runtime-cjs/public/tests/test.d.ts +0 -156
- package/build/runtime-cjs/public/tests/test.js +0 -60
- package/build/runtime-cjs/public/types.d.ts +0 -62
- package/build/runtime-cjs/public/types.js +0 -16
- package/build/runtime-cjs/router/cookies.js +0 -168
- package/build/runtime-cjs/router/jwt.js +0 -168
- package/build/runtime-cjs/router/match.d.ts +0 -39
- package/build/runtime-cjs/router/match.js +0 -158
- package/build/runtime-cjs/router/server.d.ts +0 -24
- package/build/runtime-cjs/router/server.js +0 -117
- package/build/runtime-cjs/router/session.d.ts +0 -22
- package/build/runtime-cjs/router/session.js +0 -100
- package/build/runtime-cjs/router/types.d.ts +0 -26
- package/build/runtime-cjs/router/types.js +0 -16
- package/build/runtime-cjs/server/index.d.ts +0 -17
- package/build/runtime-cjs/server/index.js +0 -62
- package/build/runtime-esm/cache/cache.d.ts +0 -169
- package/build/runtime-esm/cache/constants.d.ts +0 -1
- package/build/runtime-esm/cache/gc.d.ts +0 -10
- package/build/runtime-esm/cache/index.d.ts +0 -3
- package/build/runtime-esm/cache/index.js +0 -5
- package/build/runtime-esm/cache/lists.d.ts +0 -89
- package/build/runtime-esm/cache/staleManager.d.ts +0 -31
- package/build/runtime-esm/cache/storage.d.ts +0 -110
- package/build/runtime-esm/cache/stuff.d.ts +0 -2
- package/build/runtime-esm/cache/subscription.d.ts +0 -52
- package/build/runtime-esm/client/documentStore.d.ts +0 -107
- package/build/runtime-esm/client/index.d.ts +0 -50
- package/build/runtime-esm/client/index.js +0 -130
- package/build/runtime-esm/client/plugins/cache.d.ts +0 -9
- package/build/runtime-esm/client/plugins/cache.js +0 -104
- package/build/runtime-esm/client/plugins/fetch.d.ts +0 -38
- package/build/runtime-esm/client/plugins/fetch.js +0 -184
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +0 -9
- package/build/runtime-esm/client/plugins/fetchParams.js +0 -23
- package/build/runtime-esm/client/plugins/fragment.d.ts +0 -2
- package/build/runtime-esm/client/plugins/fragment.js +0 -53
- package/build/runtime-esm/client/plugins/index.d.ts +0 -9
- package/build/runtime-esm/client/plugins/index.js +0 -12
- package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +0 -4
- package/build/runtime-esm/client/plugins/injectedPlugins.js +0 -5
- package/build/runtime-esm/client/plugins/mutation.d.ts +0 -2
- package/build/runtime-esm/client/plugins/mutation.js +0 -65
- package/build/runtime-esm/client/plugins/optimisticKeys.d.ts +0 -7
- package/build/runtime-esm/client/plugins/optimisticKeys.js +0 -290
- package/build/runtime-esm/client/plugins/query.d.ts +0 -2
- package/build/runtime-esm/client/plugins/query.js +0 -69
- package/build/runtime-esm/client/plugins/subscription.d.ts +0 -20
- package/build/runtime-esm/client/plugins/subscription.js +0 -90
- package/build/runtime-esm/client/plugins/test.d.ts +0 -15
- package/build/runtime-esm/client/plugins/test.js +0 -93
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +0 -8
- package/build/runtime-esm/client/plugins/throwOnError.js +0 -23
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +0 -3
- package/build/runtime-esm/client/utils/documentPlugins.js +0 -33
- package/build/runtime-esm/client/utils/index.d.ts +0 -1
- package/build/runtime-esm/client/utils/index.js +0 -1
- package/build/runtime-esm/generated.d.ts +0 -5
- package/build/runtime-esm/generated.js +0 -0
- package/build/runtime-esm/imports/config.d.ts +0 -3
- package/build/runtime-esm/imports/config.js +0 -4
- package/build/runtime-esm/imports/pluginConfig.d.ts +0 -3
- package/build/runtime-esm/imports/pluginConfig.js +0 -5
- package/build/runtime-esm/index.d.ts +0 -8
- package/build/runtime-esm/index.js +0 -22
- package/build/runtime-esm/lib/config.d.ts +0 -216
- package/build/runtime-esm/lib/config.js +0 -69
- package/build/runtime-esm/lib/constants.d.ts +0 -6
- package/build/runtime-esm/lib/deepEquals.d.ts +0 -1
- package/build/runtime-esm/lib/flatten.d.ts +0 -2
- package/build/runtime-esm/lib/index.d.ts +0 -10
- package/build/runtime-esm/lib/index.js +0 -10
- package/build/runtime-esm/lib/key.d.ts +0 -6
- package/build/runtime-esm/lib/log.d.ts +0 -6
- package/build/runtime-esm/lib/lru.d.ts +0 -52
- package/build/runtime-esm/lib/pageInfo.d.ts +0 -7
- package/build/runtime-esm/lib/pagination.d.ts +0 -27
- package/build/runtime-esm/lib/scalars.d.ts +0 -14
- package/build/runtime-esm/lib/selection.d.ts +0 -2
- package/build/runtime-esm/lib/store.d.ts +0 -19
- package/build/runtime-esm/lib/types.d.ts +0 -417
- package/build/runtime-esm/public/cache.d.ts +0 -42
- package/build/runtime-esm/public/cache.js +0 -74
- package/build/runtime-esm/public/index.d.ts +0 -1
- package/build/runtime-esm/public/index.js +0 -4
- package/build/runtime-esm/public/list.d.ts +0 -18
- package/build/runtime-esm/public/list.js +0 -127
- package/build/runtime-esm/public/record.d.ts +0 -40
- package/build/runtime-esm/public/record.js +0 -70
- package/build/runtime-esm/public/tests/test.d.ts +0 -156
- package/build/runtime-esm/public/tests/test.js +0 -36
- package/build/runtime-esm/public/types.d.ts +0 -62
- package/build/runtime-esm/router/cookies.d.ts +0 -41
- package/build/runtime-esm/router/jwt.d.ts +0 -117
- package/build/runtime-esm/router/match.d.ts +0 -39
- package/build/runtime-esm/router/match.js +0 -131
- package/build/runtime-esm/router/server.d.ts +0 -24
- package/build/runtime-esm/router/server.js +0 -92
- package/build/runtime-esm/router/session.d.ts +0 -22
- package/build/runtime-esm/router/session.js +0 -74
- package/build/runtime-esm/router/types.d.ts +0 -26
- package/build/runtime-esm/router/types.js +0 -0
- package/build/runtime-esm/server/index.d.ts +0 -17
- package/build/runtime-esm/server/index.js +0 -38
- package/build/test-cjs/index.js +0 -75249
- package/build/test-cjs/package.json +0 -1
- package/build/test-esm/index.js +0 -75244
- package/build/vite/imports.d.ts +0 -40
- package/build/vite-cjs/index.js +0 -86272
- package/build/vite-cjs/package.json +0 -1
- package/build/vite-esm/index.js +0 -86264
- /package/build/{adapter-esm → adapter}/package.json +0 -0
- /package/build/{cmd-esm → cmd}/package.json +0 -0
- /package/build/{vite → lib}/ast.d.ts +0 -0
- /package/build/{codegen-esm → lib}/package.json +0 -0
- /package/build/{lib-esm → node}/package.json +0 -0
- /package/build/{runtime-esm → oauth}/package.json +0 -0
- /package/build/{runtime-cjs/router → router}/cookies.d.ts +0 -0
- /package/build/{runtime-cjs/router → router}/jwt.d.ts +0 -0
- /package/build/{test-esm → router}/package.json +0 -0
- /package/build/{runtime-esm/public → router}/types.js +0 -0
- /package/build/{runtime-esm → runtime}/cache/constants.js +0 -0
- /package/build/{runtime-esm/lib → runtime}/constants.js +0 -0
- /package/build/{runtime-cjs/lib → runtime}/deepEquals.d.ts +0 -0
- /package/build/{runtime-esm/lib → runtime}/deepEquals.js +0 -0
- /package/build/{runtime-esm/lib → runtime}/flatten.js +0 -0
- /package/build/{runtime-cjs/lib → runtime}/log.d.ts +0 -0
- /package/build/{runtime-cjs/lib → runtime}/lru.d.ts +0 -0
- /package/build/{runtime-esm/lib → runtime}/lru.js +0 -0
- /package/build/{vite-esm → runtime}/package.json +0 -0
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createInterface } from "node:readline";
|
|
6
|
+
import { WebSocket } from "ws";
|
|
7
|
+
const wasiRunnerPath = path.join(tmpdir(), "houdini-wasi-runner.mjs");
|
|
8
|
+
writeFileSync(
|
|
9
|
+
wasiRunnerPath,
|
|
10
|
+
`import{WASI}from'node:wasi';
|
|
11
|
+
import{readFileSync}from'node:fs';
|
|
12
|
+
import{Worker,isMainThread,workerData,MessageChannel,receiveMessageOnPort}from'worker_threads';
|
|
13
|
+
const[,,w,...r]=process.argv;
|
|
14
|
+
if(isMainThread){
|
|
15
|
+
const{port1:p1,port2:p2}=new MessageChannel();
|
|
16
|
+
const sb=new Int32Array(new SharedArrayBuffer(4));
|
|
17
|
+
process.stdin.on('error',()=>{});
|
|
18
|
+
process.stdin.on('data',d=>{p1.postMessage(d);Atomics.add(sb,0,1);Atomics.notify(sb,0);});
|
|
19
|
+
process.stdin.on('end',()=>{p1.postMessage(null);Atomics.add(sb,0,1);Atomics.notify(sb,0);});
|
|
20
|
+
const wk=new Worker(new URL(import.meta.url),{workerData:{w,r,p:p2,sb},transferList:[p2]});
|
|
21
|
+
wk.on('exit',c=>process.exit(c??0));
|
|
22
|
+
}else{
|
|
23
|
+
const{w:wb,r:args,p:port,sb}=workerData;
|
|
24
|
+
const wasi=new WASI({version:'preview1',args:[wb,...args],env:process.env,preopens:{'/':'/'}});
|
|
25
|
+
let mem=null;
|
|
26
|
+
const io=wasi.getImportObject();
|
|
27
|
+
const rfr=io.wasi_snapshot_preview1.fd_read;
|
|
28
|
+
io.wasi_snapshot_preview1.fd_read=(fd,iovs,il,nr)=>{
|
|
29
|
+
if(fd!==0||!mem)return rfr(fd,iovs,il,nr);
|
|
30
|
+
while(Atomics.load(sb,0)===0)Atomics.wait(sb,0,0);
|
|
31
|
+
const m=receiveMessageOnPort(port);
|
|
32
|
+
Atomics.sub(sb,0,1);
|
|
33
|
+
const v=new DataView(mem.buffer);
|
|
34
|
+
if(!m||m.message===null){v.setUint32(nr,0,true);return 0;}
|
|
35
|
+
const b=Buffer.isBuffer(m.message)?m.message:Buffer.from(m.message);
|
|
36
|
+
let wn=0;
|
|
37
|
+
for(let i=0;i<il;i++){
|
|
38
|
+
const p=v.getUint32(iovs+i*8,true),l=v.getUint32(iovs+i*8+4,true);
|
|
39
|
+
const n=Math.min(l,b.length-wn);
|
|
40
|
+
if(n<=0)break;
|
|
41
|
+
new Uint8Array(mem.buffer,p,n).set(b.subarray(wn,wn+n));
|
|
42
|
+
wn+=n;}
|
|
43
|
+
v.setUint32(nr,wn,true);
|
|
44
|
+
return 0;};
|
|
45
|
+
const mod=new WebAssembly.Module(readFileSync(wb));
|
|
46
|
+
const inst=new WebAssembly.Instance(mod,io);
|
|
47
|
+
mem=inst.exports.memory;
|
|
48
|
+
wasi.start(inst);
|
|
49
|
+
process.exit(0);}
|
|
50
|
+
`
|
|
51
|
+
);
|
|
52
|
+
import * as conventions from "../router/conventions.js";
|
|
53
|
+
import { create_schema, schema_version, write_config } from "./database.js";
|
|
54
|
+
import { openDb } from "./db.js";
|
|
55
|
+
import { format_hook_error } from "./error.js";
|
|
56
|
+
import * as fs from "./fs.js";
|
|
57
|
+
import { Logger } from "./logger.js";
|
|
58
|
+
import { LogLevel } from "./types.js";
|
|
59
|
+
async function connect_db(config) {
|
|
60
|
+
const filepath = conventions.db_path(config);
|
|
61
|
+
let db = await openDb(filepath);
|
|
62
|
+
const stamped = db.get("PRAGMA user_version")?.user_version ?? 0;
|
|
63
|
+
const existing = db.get(`SELECT 1 FROM sqlite_master WHERE type = 'table' LIMIT 1`);
|
|
64
|
+
if (existing && stamped !== schema_version) {
|
|
65
|
+
db.close();
|
|
66
|
+
try {
|
|
67
|
+
await fs.remove(filepath);
|
|
68
|
+
} catch (_e) {
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
await fs.remove(`${filepath}-shm`);
|
|
72
|
+
} catch (_e) {
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
await fs.remove(`${filepath}-wal`);
|
|
76
|
+
} catch (_e) {
|
|
77
|
+
}
|
|
78
|
+
db = await openDb(filepath);
|
|
79
|
+
}
|
|
80
|
+
db.exec(create_schema);
|
|
81
|
+
db.exec(`PRAGMA user_version = ${schema_version}`);
|
|
82
|
+
db.flush();
|
|
83
|
+
return [db, filepath];
|
|
84
|
+
}
|
|
85
|
+
async function init_db(config, preserve) {
|
|
86
|
+
const db_file = conventions.db_path(config);
|
|
87
|
+
if (!preserve) {
|
|
88
|
+
try {
|
|
89
|
+
await fs.remove(db_file);
|
|
90
|
+
} catch (_e) {
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
await fs.remove(`${db_file}-shm`);
|
|
94
|
+
} catch (_e) {
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
await fs.remove(`${db_file}-wal`);
|
|
98
|
+
} catch (_e) {
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return connect_db(config);
|
|
102
|
+
}
|
|
103
|
+
function plugin_db_key(name) {
|
|
104
|
+
if (!name.startsWith("./") && !name.startsWith("../") && !path.isAbsolute(name)) {
|
|
105
|
+
return name;
|
|
106
|
+
}
|
|
107
|
+
return name.replace(/\./g, "_").replace(/\//g, "__");
|
|
108
|
+
}
|
|
109
|
+
async function codegen_setup(config, mode, db, db_file) {
|
|
110
|
+
const _db = db;
|
|
111
|
+
const logger = new Logger(config.config_file.logLevel ?? LogLevel.ShortSummary);
|
|
112
|
+
await fs.mkdirpSync(conventions.houdini_root(config));
|
|
113
|
+
const rawTransport = config.config_file.pluginTransport ?? "websocket";
|
|
114
|
+
const resolvedTransport = rawTransport.startsWith("env:") ? process.env[rawTransport.slice("env:".length)] ?? "websocket" : rawTransport;
|
|
115
|
+
const useStdio = resolvedTransport === "stdio";
|
|
116
|
+
const plugins = {};
|
|
117
|
+
const plugin_specs = [];
|
|
118
|
+
const spec_results = {};
|
|
119
|
+
const stdioStdin = /* @__PURE__ */ new Map();
|
|
120
|
+
const triggerHookRef = { fn: null };
|
|
121
|
+
const pendingRequests = /* @__PURE__ */ new Map();
|
|
122
|
+
const wait_for_plugin_db = async (configKey, dbKey) => {
|
|
123
|
+
const pollDb = await openDb(db_file);
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
const interval = setInterval(() => {
|
|
126
|
+
try {
|
|
127
|
+
pollDb.reload();
|
|
128
|
+
const row = pollDb.get("SELECT * FROM plugins WHERE name = ?", [dbKey]);
|
|
129
|
+
if (row) {
|
|
130
|
+
clearInterval(interval);
|
|
131
|
+
clearTimeout(timeout);
|
|
132
|
+
pollDb.run("UPDATE plugins SET config = ? WHERE name = ?", [
|
|
133
|
+
JSON.stringify(
|
|
134
|
+
config.plugins.find((p) => p.name === configKey)?.config ?? {}
|
|
135
|
+
),
|
|
136
|
+
dbKey
|
|
137
|
+
]);
|
|
138
|
+
pollDb.flush();
|
|
139
|
+
pollDb.close();
|
|
140
|
+
const spec = {
|
|
141
|
+
name: row.name,
|
|
142
|
+
port: row.port,
|
|
143
|
+
hooks: new Set(JSON.parse(row.hooks)),
|
|
144
|
+
order: row.plugin_order,
|
|
145
|
+
directory: config.plugins.find((p) => p.name === configKey)?.directory || ""
|
|
146
|
+
};
|
|
147
|
+
spec_results[configKey] = spec;
|
|
148
|
+
if (row.config_module) {
|
|
149
|
+
import(row.config_module).then((module) => {
|
|
150
|
+
if (module && typeof module.default === "function") {
|
|
151
|
+
config.config_file = module.default(config.config_file);
|
|
152
|
+
}
|
|
153
|
+
resolve(spec);
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
resolve(spec);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
clearInterval(interval);
|
|
161
|
+
clearTimeout(timeout);
|
|
162
|
+
pollDb.close();
|
|
163
|
+
reject(err);
|
|
164
|
+
}
|
|
165
|
+
}, 10);
|
|
166
|
+
const timeout = setTimeout(() => {
|
|
167
|
+
clearInterval(interval);
|
|
168
|
+
pollDb.close();
|
|
169
|
+
reject(new Error(`Timeout waiting for plugin ${configKey} to register`));
|
|
170
|
+
}, 1e4);
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const wait_for_plugin_stdio = (name, child) => new Promise((resolve, reject) => {
|
|
174
|
+
const timeout = setTimeout(() => {
|
|
175
|
+
reject(new Error(`Timeout waiting for plugin ${name} to register`));
|
|
176
|
+
}, 1e4);
|
|
177
|
+
const rl = createInterface({ input: child.stdout });
|
|
178
|
+
let registered = false;
|
|
179
|
+
rl.on("line", (line) => {
|
|
180
|
+
try {
|
|
181
|
+
const msg = JSON.parse(line);
|
|
182
|
+
if (!registered) {
|
|
183
|
+
if (msg.type !== "register") {
|
|
184
|
+
clearTimeout(timeout);
|
|
185
|
+
reject(new Error(`Plugin ${name} sent ${msg.type} before registering`));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
registered = true;
|
|
189
|
+
clearTimeout(timeout);
|
|
190
|
+
const spec = {
|
|
191
|
+
name: msg.name ?? plugin_db_key(name),
|
|
192
|
+
port: msg.port ?? 0,
|
|
193
|
+
hooks: new Set(msg.hooks ?? []),
|
|
194
|
+
order: msg.order,
|
|
195
|
+
directory: config.plugins.find((p) => p.name === name)?.directory || ""
|
|
196
|
+
};
|
|
197
|
+
spec_results[name] = spec;
|
|
198
|
+
_db.run(
|
|
199
|
+
`INSERT OR IGNORE INTO plugins (name, hooks, port, plugin_order, include_runtime, include_static_runtime, config_module, client_plugins)
|
|
200
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
201
|
+
[
|
|
202
|
+
spec.name,
|
|
203
|
+
JSON.stringify([...spec.hooks]),
|
|
204
|
+
spec.port,
|
|
205
|
+
spec.order,
|
|
206
|
+
msg.includeRuntime ?? null,
|
|
207
|
+
msg.includeStaticRuntime ?? null,
|
|
208
|
+
msg.configModule ?? null,
|
|
209
|
+
msg.clientPlugins ?? null
|
|
210
|
+
]
|
|
211
|
+
);
|
|
212
|
+
_db.run("UPDATE plugins SET config = ? WHERE name = ?", [
|
|
213
|
+
JSON.stringify(
|
|
214
|
+
config.plugins.find((p) => p.name === name)?.config ?? {}
|
|
215
|
+
),
|
|
216
|
+
spec.name
|
|
217
|
+
]);
|
|
218
|
+
_db.flush();
|
|
219
|
+
if (msg.configModule) {
|
|
220
|
+
import(msg.configModule).then((module) => {
|
|
221
|
+
if (module && typeof module.default === "function") {
|
|
222
|
+
config.config_file = module.default(config.config_file);
|
|
223
|
+
}
|
|
224
|
+
resolve(spec);
|
|
225
|
+
}).catch((err) => {
|
|
226
|
+
reject(
|
|
227
|
+
new Error(
|
|
228
|
+
`Failed to load configModule for ${name}: ${err.message}`
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
resolve(spec);
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (msg.type === "response") {
|
|
238
|
+
const pending = pendingRequests.get(msg.id);
|
|
239
|
+
if (!pending) return;
|
|
240
|
+
clearTimeout(pending.timeout);
|
|
241
|
+
pendingRequests.delete(msg.id);
|
|
242
|
+
if (msg.error) {
|
|
243
|
+
const errors = Array.isArray(msg.error) ? msg.error : [msg.error];
|
|
244
|
+
errors.forEach((error) => {
|
|
245
|
+
format_hook_error(config.root_dir, error, name, pending.hook);
|
|
246
|
+
});
|
|
247
|
+
pending.reject(
|
|
248
|
+
Object.assign(new Error(`Failed to call ${name}`), {
|
|
249
|
+
alreadyLogged: true
|
|
250
|
+
})
|
|
251
|
+
);
|
|
252
|
+
} else {
|
|
253
|
+
pending.resolve(msg.result);
|
|
254
|
+
}
|
|
255
|
+
} else if (msg.type === "invoke") {
|
|
256
|
+
if (!triggerHookRef.fn) {
|
|
257
|
+
const reply = `${JSON.stringify({
|
|
258
|
+
id: msg.id,
|
|
259
|
+
type: "invoke_result",
|
|
260
|
+
error: { message: "orchestrator not ready" }
|
|
261
|
+
})}
|
|
262
|
+
`;
|
|
263
|
+
child.stdin?.write(reply);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
triggerHookRef.fn(msg.hook, {
|
|
267
|
+
parallel_safe: msg.parallel,
|
|
268
|
+
payload: msg.payload,
|
|
269
|
+
task_id: msg.taskId
|
|
270
|
+
}).then((result) => {
|
|
271
|
+
const reply = JSON.stringify({ id: msg.id, type: "invoke_result", result }) + "\n";
|
|
272
|
+
child.stdin?.write(reply);
|
|
273
|
+
}).catch((err) => {
|
|
274
|
+
const reply = `${JSON.stringify({
|
|
275
|
+
id: msg.id,
|
|
276
|
+
type: "invoke_result",
|
|
277
|
+
error: { message: err.message }
|
|
278
|
+
})}
|
|
279
|
+
`;
|
|
280
|
+
child.stdin?.write(reply);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
} catch (err) {
|
|
284
|
+
if (!registered) {
|
|
285
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
rl.on("close", () => {
|
|
290
|
+
if (!registered) {
|
|
291
|
+
clearTimeout(timeout);
|
|
292
|
+
reject(new Error(`Plugin ${name} stdout closed before registering`));
|
|
293
|
+
} else {
|
|
294
|
+
for (const [id, pending] of pendingRequests.entries()) {
|
|
295
|
+
if (pending.plugin !== name) continue;
|
|
296
|
+
clearTimeout(pending.timeout);
|
|
297
|
+
pendingRequests.delete(id);
|
|
298
|
+
pending.reject(new Error(`Plugin ${name} closed unexpectedly`));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
_db.run("DELETE FROM plugins");
|
|
304
|
+
_db.flush();
|
|
305
|
+
logger.time("Start Plugins");
|
|
306
|
+
await Promise.all(
|
|
307
|
+
config.plugins.map(async (plugin) => {
|
|
308
|
+
let executable = plugin.executable;
|
|
309
|
+
const args = ["--database", db_file];
|
|
310
|
+
const jsExtensions = [".js", ".mjs", ".cjs"];
|
|
311
|
+
if (jsExtensions.includes(path.extname(plugin.executable))) {
|
|
312
|
+
executable = "node";
|
|
313
|
+
args.unshift(plugin.executable);
|
|
314
|
+
} else if (path.extname(plugin.executable) === ".wasm") {
|
|
315
|
+
executable = "node";
|
|
316
|
+
args.unshift(wasiRunnerPath, plugin.executable);
|
|
317
|
+
}
|
|
318
|
+
const dbKey = plugin_db_key(plugin.name);
|
|
319
|
+
args.push("--plugin-key", dbKey);
|
|
320
|
+
const pluginUsesStdio = useStdio || path.extname(plugin.executable) === ".wasm";
|
|
321
|
+
if (pluginUsesStdio) {
|
|
322
|
+
args.push("--transport", "stdio");
|
|
323
|
+
}
|
|
324
|
+
logger.time(`Spawn ${plugin.name}`);
|
|
325
|
+
const child = spawn(executable, args, {
|
|
326
|
+
// stdio/WASM plugins carry the protocol over stdin+stdout, so those must be pipes.
|
|
327
|
+
// websocket plugins talk over TCP, so let stdout/stderr through to the console.
|
|
328
|
+
stdio: pluginUsesStdio ? ["pipe", "pipe", "inherit"] : ["inherit", "inherit", "inherit"],
|
|
329
|
+
detached: process.platform !== "win32"
|
|
330
|
+
});
|
|
331
|
+
if (pluginUsesStdio) {
|
|
332
|
+
stdioStdin.set(dbKey, child.stdin);
|
|
333
|
+
child.stdin.on("error", (err) => {
|
|
334
|
+
if (err.code !== "EPIPE") {
|
|
335
|
+
console.error(`[${plugin.name}] stdin error:`, err.message);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
plugins[plugin.name] = {
|
|
340
|
+
process: child,
|
|
341
|
+
...await (pluginUsesStdio ? wait_for_plugin_stdio(plugin.name, child) : wait_for_plugin_db(plugin.name, dbKey))
|
|
342
|
+
};
|
|
343
|
+
logger.timeEnd(`Spawn ${plugin.name}`, LogLevel.Verbose);
|
|
344
|
+
})
|
|
345
|
+
);
|
|
346
|
+
for (const plugin of config.plugins) {
|
|
347
|
+
plugin_specs.push(spec_results[plugin.name]);
|
|
348
|
+
}
|
|
349
|
+
logger.timeEnd("Start Plugins", LogLevel.Summary);
|
|
350
|
+
const wsConnections = /* @__PURE__ */ new Map();
|
|
351
|
+
let messageCounter = 0;
|
|
352
|
+
async function getOrCreateWS(name, port) {
|
|
353
|
+
const existing = wsConnections.get(name);
|
|
354
|
+
if (existing && existing.readyState === WebSocket.OPEN) {
|
|
355
|
+
return existing;
|
|
356
|
+
}
|
|
357
|
+
return new Promise((resolve, reject) => {
|
|
358
|
+
const wsUrl = `ws://localhost:${port}/ws`;
|
|
359
|
+
const ws = new WebSocket(wsUrl);
|
|
360
|
+
ws.on("open", () => {
|
|
361
|
+
wsConnections.set(name, ws);
|
|
362
|
+
return resolve(ws);
|
|
363
|
+
});
|
|
364
|
+
ws.on("message", (data) => {
|
|
365
|
+
try {
|
|
366
|
+
const response = JSON.parse(data.toString());
|
|
367
|
+
const pending = pendingRequests.get(response.id);
|
|
368
|
+
if (!pending) return;
|
|
369
|
+
clearTimeout(pending.timeout);
|
|
370
|
+
pendingRequests.delete(response.id);
|
|
371
|
+
switch (response.type) {
|
|
372
|
+
case "error":
|
|
373
|
+
console.error(`! [${name}] ${response.error}`);
|
|
374
|
+
pending.reject(new Error(`${name}: ${response.error}`));
|
|
375
|
+
break;
|
|
376
|
+
case "response":
|
|
377
|
+
if (response.error) {
|
|
378
|
+
const errors = Array.isArray(response.error) ? response.error : [response.error];
|
|
379
|
+
errors.forEach((error) => {
|
|
380
|
+
format_hook_error(config.root_dir, error, name, pending.hook);
|
|
381
|
+
});
|
|
382
|
+
pending.reject(
|
|
383
|
+
Object.assign(new Error(`Failed to call ${name}`), {
|
|
384
|
+
alreadyLogged: true
|
|
385
|
+
})
|
|
386
|
+
);
|
|
387
|
+
} else {
|
|
388
|
+
pending.resolve(response.result);
|
|
389
|
+
}
|
|
390
|
+
break;
|
|
391
|
+
default:
|
|
392
|
+
console.warn(`[${name}] Unknown message type: ${response.type}`);
|
|
393
|
+
pending.reject(new Error(`Unknown message type: ${response.type}`));
|
|
394
|
+
}
|
|
395
|
+
} catch (err) {
|
|
396
|
+
console.error(`Error processing WebSocket message for ${name}:`, err);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
ws.on("error", (err) => {
|
|
400
|
+
console.error(`WebSocket error for ${name}:`, err);
|
|
401
|
+
wsConnections.delete(name);
|
|
402
|
+
reject(new Error(`WebSocket error for ${name}: ${err}`));
|
|
403
|
+
});
|
|
404
|
+
ws.on("close", () => {
|
|
405
|
+
wsConnections.delete(name);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
const invoke_hook = async (name, hook, payload = {}, task_id) => {
|
|
410
|
+
const plugin = plugin_specs.find((spec) => spec.name === name);
|
|
411
|
+
if (!plugin) {
|
|
412
|
+
throw new Error(`unknown plugin: ${name}`);
|
|
413
|
+
}
|
|
414
|
+
const { port, directory } = plugin;
|
|
415
|
+
const messageId = String(++messageCounter);
|
|
416
|
+
const message = {
|
|
417
|
+
id: messageId,
|
|
418
|
+
type: "request",
|
|
419
|
+
hook,
|
|
420
|
+
payload,
|
|
421
|
+
taskId: task_id,
|
|
422
|
+
pluginDirectory: directory
|
|
423
|
+
};
|
|
424
|
+
if (useStdio) {
|
|
425
|
+
const stdin = stdioStdin.get(name);
|
|
426
|
+
if (!stdin) {
|
|
427
|
+
throw new Error(`No stdio channel for plugin ${name}`);
|
|
428
|
+
}
|
|
429
|
+
return new Promise((resolve, reject) => {
|
|
430
|
+
const timeout = setTimeout(() => {
|
|
431
|
+
pendingRequests.delete(messageId);
|
|
432
|
+
reject(new Error(`Request timeout for ${name}/${hook}`));
|
|
433
|
+
}, 3e4);
|
|
434
|
+
pendingRequests.set(messageId, { resolve, reject, timeout, hook, plugin: name });
|
|
435
|
+
stdin.write(`${JSON.stringify(message)}
|
|
436
|
+
`);
|
|
437
|
+
});
|
|
438
|
+
} else {
|
|
439
|
+
const ws = await getOrCreateWS(name, port);
|
|
440
|
+
return new Promise((resolve, reject) => {
|
|
441
|
+
const timeout = setTimeout(() => {
|
|
442
|
+
pendingRequests.delete(messageId);
|
|
443
|
+
reject(new Error(`WebSocket request timeout for ${name}/${hook}`));
|
|
444
|
+
}, 3e4);
|
|
445
|
+
pendingRequests.set(messageId, { resolve, reject, timeout, hook, plugin: name });
|
|
446
|
+
ws.send(JSON.stringify(message));
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
_db.reload();
|
|
451
|
+
const _fireHook = async (hook, {
|
|
452
|
+
parallel_safe,
|
|
453
|
+
payload,
|
|
454
|
+
task_id
|
|
455
|
+
} = {}) => {
|
|
456
|
+
const timeName = hook + (task_id ? ` (${task_id})` : "");
|
|
457
|
+
logger.time(timeName);
|
|
458
|
+
const plugins2 = plugin_specs.filter(({ hooks }) => hooks.has(hook));
|
|
459
|
+
const result = {};
|
|
460
|
+
try {
|
|
461
|
+
if (parallel_safe) {
|
|
462
|
+
await Promise.all(
|
|
463
|
+
plugins2.map(async (plugin) => {
|
|
464
|
+
result[plugin.name] = await invoke_hook(plugin.name, hook, payload, task_id);
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
} else {
|
|
468
|
+
for (const { name } of plugins2) {
|
|
469
|
+
result[name] = await invoke_hook(name, hook, payload, task_id);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
} finally {
|
|
473
|
+
logger.timeEnd(timeName, task_id ? LogLevel.Verbose : LogLevel.Summary);
|
|
474
|
+
}
|
|
475
|
+
return result;
|
|
476
|
+
};
|
|
477
|
+
const trigger_hook = async (hook, opts) => {
|
|
478
|
+
_db.flush();
|
|
479
|
+
const result = await _fireHook(hook, opts);
|
|
480
|
+
_db.reload();
|
|
481
|
+
return result;
|
|
482
|
+
};
|
|
483
|
+
triggerHookRef.fn = trigger_hook;
|
|
484
|
+
await write_config(_db, config, invoke_hook, plugin_specs, mode, logger);
|
|
485
|
+
_db.flush();
|
|
486
|
+
await trigger_hook("Config");
|
|
487
|
+
await trigger_hook("AfterLoad");
|
|
488
|
+
await trigger_hook("Schema");
|
|
489
|
+
let pipelineQueue = Promise.resolve();
|
|
490
|
+
return {
|
|
491
|
+
database_path: db_file,
|
|
492
|
+
trigger_hook,
|
|
493
|
+
run_pipeline: (options) => run_pipeline(trigger_hook, options),
|
|
494
|
+
pipeline_lock: (fn) => {
|
|
495
|
+
const result = pipelineQueue.then(fn);
|
|
496
|
+
pipelineQueue = result.then(
|
|
497
|
+
() => {
|
|
498
|
+
},
|
|
499
|
+
() => {
|
|
500
|
+
}
|
|
501
|
+
);
|
|
502
|
+
return result;
|
|
503
|
+
},
|
|
504
|
+
close: async () => {
|
|
505
|
+
for (const [name, ws] of wsConnections.entries()) {
|
|
506
|
+
try {
|
|
507
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
508
|
+
ws.close(1001, "shutdown");
|
|
509
|
+
}
|
|
510
|
+
} catch (err) {
|
|
511
|
+
console.error(`Error closing WebSocket for ${name}:`, err);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
wsConnections.clear();
|
|
515
|
+
for (const [, stdin] of stdioStdin.entries()) {
|
|
516
|
+
try {
|
|
517
|
+
stdin.end();
|
|
518
|
+
} catch {
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
stdioStdin.clear();
|
|
522
|
+
for (const [, { timeout, reject }] of pendingRequests.entries()) {
|
|
523
|
+
clearTimeout(timeout);
|
|
524
|
+
reject(new Error("codegen closed"));
|
|
525
|
+
}
|
|
526
|
+
pendingRequests.clear();
|
|
527
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
528
|
+
try {
|
|
529
|
+
db.close();
|
|
530
|
+
} catch {
|
|
531
|
+
}
|
|
532
|
+
await Promise.all(
|
|
533
|
+
Object.entries(plugins).map(async ([, plugin]) => {
|
|
534
|
+
if (plugin.process.pid) {
|
|
535
|
+
if (process.platform === "win32") {
|
|
536
|
+
try {
|
|
537
|
+
spawn("taskkill", [
|
|
538
|
+
"/pid",
|
|
539
|
+
plugin.process.pid.toString(),
|
|
540
|
+
"/f",
|
|
541
|
+
"/t"
|
|
542
|
+
]);
|
|
543
|
+
} catch (_err) {
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
try {
|
|
547
|
+
process.kill(plugin.process.pid, 0);
|
|
548
|
+
process.kill(-plugin.process.pid, "SIGINT");
|
|
549
|
+
} catch {
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
})
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
const PIPELINE_HOOKS = [
|
|
559
|
+
"Config",
|
|
560
|
+
"AfterLoad",
|
|
561
|
+
"Schema",
|
|
562
|
+
"ExtractDocuments",
|
|
563
|
+
"AfterExtract",
|
|
564
|
+
"BeforeValidate",
|
|
565
|
+
"Validate",
|
|
566
|
+
"AfterValidate",
|
|
567
|
+
"BeforeGenerate",
|
|
568
|
+
"GenerateDocuments",
|
|
569
|
+
"GenerateRuntime",
|
|
570
|
+
"AfterGenerate"
|
|
571
|
+
];
|
|
572
|
+
async function run_pipeline(trigger_hook, options = {}) {
|
|
573
|
+
const { task_id, after, start, through } = options;
|
|
574
|
+
const results = {};
|
|
575
|
+
let startIndex = 0;
|
|
576
|
+
let endIndex = PIPELINE_HOOKS.length - 1;
|
|
577
|
+
if (after) {
|
|
578
|
+
const afterIndex = PIPELINE_HOOKS.indexOf(after);
|
|
579
|
+
if (afterIndex === -1) {
|
|
580
|
+
throw new Error(`Unknown hook: ${after}`);
|
|
581
|
+
}
|
|
582
|
+
startIndex = afterIndex + 1;
|
|
583
|
+
}
|
|
584
|
+
if (start) {
|
|
585
|
+
const index = PIPELINE_HOOKS.indexOf(start);
|
|
586
|
+
if (index === -1) {
|
|
587
|
+
throw new Error(`Unknown hook: ${after}`);
|
|
588
|
+
}
|
|
589
|
+
startIndex = index;
|
|
590
|
+
}
|
|
591
|
+
if (through) {
|
|
592
|
+
endIndex = PIPELINE_HOOKS.indexOf(through);
|
|
593
|
+
if (endIndex === -1) {
|
|
594
|
+
throw new Error(`Unknown hook: ${through}`);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (startIndex > endIndex) {
|
|
598
|
+
return results;
|
|
599
|
+
}
|
|
600
|
+
for (let i = startIndex; i <= endIndex; i++) {
|
|
601
|
+
const hook = PIPELINE_HOOKS[i];
|
|
602
|
+
const opts = { task_id };
|
|
603
|
+
if (hook === "Validate" || hook === "GenerateDocuments") {
|
|
604
|
+
opts.parallel_safe = true;
|
|
605
|
+
}
|
|
606
|
+
if (hook === "GenerateDocuments" && i + 1 <= endIndex && PIPELINE_HOOKS[i + 1] === "GenerateRuntime") {
|
|
607
|
+
const [gdResult, grResult] = await Promise.all([
|
|
608
|
+
trigger_hook("GenerateDocuments", { task_id, parallel_safe: true }),
|
|
609
|
+
trigger_hook("GenerateRuntime", { task_id })
|
|
610
|
+
]);
|
|
611
|
+
results.GenerateDocuments = gdResult;
|
|
612
|
+
results.GenerateRuntime = grResult;
|
|
613
|
+
i++;
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
results[hook] = await trigger_hook(hook, opts);
|
|
617
|
+
}
|
|
618
|
+
return results;
|
|
619
|
+
}
|
|
620
|
+
export {
|
|
621
|
+
PIPELINE_HOOKS,
|
|
622
|
+
codegen_setup,
|
|
623
|
+
connect_db,
|
|
624
|
+
init_db,
|
|
625
|
+
plugin_db_key,
|
|
626
|
+
run_pipeline
|
|
627
|
+
};
|