graphile-config 0.0.1-0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE.md +20 -0
- package/README.md +167 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +21 -0
- package/dist/cli.js.map +1 -0
- package/dist/hooks.d.ts +15 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +77 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +32 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +3 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/loadConfig.d.ts +3 -0
- package/dist/loadConfig.d.ts.map +1 -0
- package/dist/loadConfig.js +93 -0
- package/dist/loadConfig.js.map +1 -0
- package/dist/resolvePresets.d.ts +7 -0
- package/dist/resolvePresets.d.ts.map +1 -0
- package/dist/resolvePresets.js +169 -0
- package/dist/resolvePresets.js.map +1 -0
- package/dist/sort.d.ts +8 -0
- package/dist/sort.d.ts.map +1 -0
- package/dist/sort.js +89 -0
- package/dist/sort.js.map +1 -0
- package/package.json +63 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# graphile-config
|
|
2
|
+
|
|
3
|
+
## 0.0.1-0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#125](https://github.com/benjie/postgraphile-private/pull/125)
|
|
8
|
+
[`91f2256b3`](https://github.com/benjie/postgraphile-private/commit/91f2256b3fd699bec19fc86f1ca79df057e58639)
|
|
9
|
+
Thanks [@benjie](https://github.com/benjie)! - Initial changesets release
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © `2022` Benjie Gillam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# graphile-config
|
|
2
|
+
|
|
3
|
+
[](https://github.com/sponsors/benjie)
|
|
4
|
+
[](https://patreon.com/benjie)
|
|
5
|
+
[](http://discord.gg/graphile)
|
|
6
|
+
[](https://twitter.com/GraphileHQ)
|
|
7
|
+
|
|
8
|
+
**PRERELEASE**: this is pre-release software; use at your own risk. This will
|
|
9
|
+
likely change a lot before it's ultimately released.
|
|
10
|
+
|
|
11
|
+
`graphile-config` provides a standard plugin interface and helpers that can be
|
|
12
|
+
used across the entire of the Graphile suite. Primarily users will only use this
|
|
13
|
+
as `import type Plugin from 'graphile-config';` so that they can export plugins.
|
|
14
|
+
|
|
15
|
+
This package provides two interfaces: `Plugin` and `Preset` (alias `Config`).
|
|
16
|
+
|
|
17
|
+
## Plugin
|
|
18
|
+
|
|
19
|
+
A plugin is responsible for adding capabilities to a Graphile package. Each
|
|
20
|
+
Graphile package will register its own "scope" within the plugin's spec;
|
|
21
|
+
commonly these scopes may contain capabilities such as 'hooks' or 'events' which
|
|
22
|
+
this package attempts to standardize.
|
|
23
|
+
|
|
24
|
+
A Graphile Plugin is an object with the following properties:
|
|
25
|
+
|
|
26
|
+
- `name` (`string`): The name of the plugin, this must be unique and will be
|
|
27
|
+
used for capabilities such as `skipPlugins`
|
|
28
|
+
- `version` (`string`): a semver-compliant version for the plugin, this would
|
|
29
|
+
normally match the version in the `package.json` but does not need to (e.g. if
|
|
30
|
+
the module in question contains multiple plugins)
|
|
31
|
+
- `description` (optional `string`): human-readable description of the plugin in
|
|
32
|
+
[CommonMark](https://commonmark.org/) (markdown) format.
|
|
33
|
+
- `provides` (optional `string[]`): an optional list of "feature labels" that
|
|
34
|
+
this plugin provides, this is primarily used to govern the order in which the
|
|
35
|
+
plugin (and its hooks and events) are executed. Feature labels must be unique
|
|
36
|
+
within the list of loaded plugins, for example two different plugins should
|
|
37
|
+
not both provide `subscriptions`. If unspecified, defaults to the plugin name.
|
|
38
|
+
- `after` (optional `string[]`): indicates that this plugin should be loaded
|
|
39
|
+
after the named features (if present)
|
|
40
|
+
- `before` (optional `string[]`): indicates that this plugin should be loaded
|
|
41
|
+
before the named features (if present)
|
|
42
|
+
|
|
43
|
+
In addition to the properties above, plugins may also contain properties for
|
|
44
|
+
each of the supported scopes, for example there may be a `postgraphile` scope
|
|
45
|
+
for PostGraphile, or a `worker` scope for Graphile Worker. The value for each of
|
|
46
|
+
these scopes will be an object, but the contents of that object are defined by
|
|
47
|
+
the projects in question.
|
|
48
|
+
|
|
49
|
+
**NOTE**: Currently this plugin system is only intended for Graphile usage (and
|
|
50
|
+
thus we do not need to "reserve" keys), but should you find it useful for other
|
|
51
|
+
projects please reach out via GitHub issues and we can discuss what's necessary
|
|
52
|
+
to make this more universal. Should you decide to not heed this advice, please
|
|
53
|
+
at least make sure that the "scopes" you add are namespaced in a way to avoid
|
|
54
|
+
future conflicts with features we may wish to add.
|
|
55
|
+
|
|
56
|
+
## Preset
|
|
57
|
+
|
|
58
|
+
A preset bundles together a list of plugins, and options for various of the
|
|
59
|
+
"scopes". You may use more than one preset at a time, and presets may also
|
|
60
|
+
compose (extend) other presets. When a library is passed a list of presets it
|
|
61
|
+
results in a resolved preset (a preset that has no "extends") using the
|
|
62
|
+
`ResolvePresets` algorithm; broadly all the `extends` are resolved in order, the
|
|
63
|
+
plugins specified are merged as a set (each plugin will only be included once)
|
|
64
|
+
and the options are merged via object merging such that the options specified
|
|
65
|
+
last win.
|
|
66
|
+
|
|
67
|
+
**NOTE**: if you compose two presets (PresetA and PresetB) that both `extends`
|
|
68
|
+
the same underlying preset (BASE) and apply some overrides, then the overrides
|
|
69
|
+
in PresetA will be overridden by re-applying the BASE preset again. For this
|
|
70
|
+
reason, presets that are expected to be combined with other presets should not
|
|
71
|
+
`extends` common/shared presets, instead the end-user should be expected to add
|
|
72
|
+
these presets themselves.
|
|
73
|
+
|
|
74
|
+
**NOTE**: the order of presets is significant.
|
|
75
|
+
|
|
76
|
+
ResolvePresets(presets):
|
|
77
|
+
|
|
78
|
+
1. Let {finalPreset} be an empty preset.
|
|
79
|
+
1. For each {preset} in {presets}:
|
|
80
|
+
1. Let {resolvedPreset} be {ResolvePreset(preset)}.
|
|
81
|
+
1. Let {finalPreset} be {MergePreset(finalPreset, resolvedPreset)}.
|
|
82
|
+
1. Return {finalPreset}.
|
|
83
|
+
|
|
84
|
+
ResolvePreset(preset):
|
|
85
|
+
|
|
86
|
+
1. Let {presets} be the list specified in the {extends} property of {preset} (or
|
|
87
|
+
an empty list if none specified).
|
|
88
|
+
1. Let {basePreset} be {ResolvePresets(presets)}.
|
|
89
|
+
1. Return {MergePreset(basePreset, preset)}.
|
|
90
|
+
|
|
91
|
+
MergePreset(basePreset, extendingPreset):
|
|
92
|
+
|
|
93
|
+
1. Let {finalPreset} be an empty preset.
|
|
94
|
+
1. Assert: {basePreset} has an empty or non-existent {extends} property.
|
|
95
|
+
1. Let {plugins} be the list of plugins defined in {basePreset} union the list
|
|
96
|
+
of plugins in {extendingPreset}.
|
|
97
|
+
1. Let the list of plugins for {finalPreset} be {plugins}.
|
|
98
|
+
1. Let {scopes} be the list of scopes defined in {basePreset} union the list of
|
|
99
|
+
scopes in {extendingPreset}.
|
|
100
|
+
1. For each {scope} in {scopes}:
|
|
101
|
+
1. Let {baseScope} be the {scope} in {basePreset}.
|
|
102
|
+
1. Let {extendingScope} be the {scope} in {extendingPreset}.
|
|
103
|
+
1. If {baseScope} and {extendingScope} both exist:
|
|
104
|
+
1. Let {scope} in {finalPreset} be the result of merging {baseScope} and
|
|
105
|
+
{extendingScope} akin to
|
|
106
|
+
`Object.assign({}, baseScope, extendingScope)`.
|
|
107
|
+
1. Else: let {scope} in {finalPreset} be whichever of {baseScope} and
|
|
108
|
+
{extendingScope} actually exist.
|
|
109
|
+
1. Return {finalPreset}.
|
|
110
|
+
|
|
111
|
+
<!-- SPONSORS_BEGIN -->
|
|
112
|
+
|
|
113
|
+
## Crowd-funded open-source software
|
|
114
|
+
|
|
115
|
+
To help us develop this software sustainably under the MIT license, we ask all
|
|
116
|
+
individuals and businesses that use it to help support its ongoing maintenance
|
|
117
|
+
and development via sponsorship.
|
|
118
|
+
|
|
119
|
+
### [Click here to find out more about sponsors and sponsorship.](https://www.graphile.org/sponsor/)
|
|
120
|
+
|
|
121
|
+
And please give some love to our featured sponsors 🤩:
|
|
122
|
+
|
|
123
|
+
<table><tr>
|
|
124
|
+
<td align="center"><a href="https://surge.io/"><img src="https://graphile.org/images/sponsors/surge.png" width="90" height="90" alt="Surge" /><br />Surge</a> *</td>
|
|
125
|
+
<td align="center"><a href="https://www.netflix.com/"><img src="https://graphile.org/images/sponsors/Netflix.png" width="90" height="90" alt="Netflix" /><br />Netflix</a> *</td>
|
|
126
|
+
<td align="center"><a href="https://qwick.com/"><img src="https://graphile.org/images/sponsors/qwick.png" width="90" height="90" alt="Qwick" /><br />Qwick</a> *</td>
|
|
127
|
+
<td align="center"><a href="https://www.the-guild.dev/"><img src="https://graphile.org/images/sponsors/theguild.png" width="90" height="90" alt="The Guild" /><br />The Guild</a> *</td>
|
|
128
|
+
</tr><tr>
|
|
129
|
+
<td align="center"><a href="http://chads.website"><img src="https://graphile.org/images/sponsors/chadf.png" width="90" height="90" alt="Chad Furman" /><br />Chad Furman</a> *</td>
|
|
130
|
+
<td align="center"><a href="https://www.fanatics.com/"><img src="https://graphile.org/images/sponsors/fanatics.png" width="90" height="90" alt="Fanatics" /><br />Fanatics</a> *</td>
|
|
131
|
+
<td align="center"><a href="https://dovetailapp.com/"><img src="https://graphile.org/images/sponsors/dovetail.png" width="90" height="90" alt="Dovetail" /><br />Dovetail</a> *</td>
|
|
132
|
+
<td align="center"><a href="https://www.enzuzo.com/"><img src="https://graphile.org/images/sponsors/enzuzo.png" width="90" height="90" alt="Enzuzo" /><br />Enzuzo</a> *</td>
|
|
133
|
+
</tr><tr>
|
|
134
|
+
<td align="center"><a href="https://stellate.co/"><img src="https://graphile.org/images/sponsors/Stellate.png" width="90" height="90" alt="Stellate" /><br />Stellate</a> *</td>
|
|
135
|
+
</tr></table>
|
|
136
|
+
|
|
137
|
+
<em>\* Sponsors the entire Graphile suite</em>
|
|
138
|
+
|
|
139
|
+
<!-- SPONSORS_END -->
|
|
140
|
+
|
|
141
|
+
## Supporting TypeScript ESM
|
|
142
|
+
|
|
143
|
+
You can specify a `graphile.config.ts` file; but if that uses `export default`
|
|
144
|
+
and your TypeScript is configured to export ESM then you'll get an error telling
|
|
145
|
+
you that you cannot `require` an ES Module:
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/graphile.config.ts
|
|
149
|
+
require() of ES modules is not supported.
|
|
150
|
+
require() of /path/to/graphile.config.ts from /path/to/node_modules/graphile-config/dist/loadConfig.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
|
|
151
|
+
Instead change the requiring code to use import(), or remove "type": "module" from /path/to/package.json.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Or, in newer versions, an error saying unknown file extension:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /path/to/graphile.config.ts
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
To solve this, use the experimental loaders API to add support for TS ESM via
|
|
161
|
+
the `ts-node/esm` loader:
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
export NODE_OPTIONS="$NODE_OPTIONS --loader ts-node/esm"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Then run your command again.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Argv } from "yargs";
|
|
2
|
+
import yargs from "yargs";
|
|
3
|
+
export { Argv };
|
|
4
|
+
export declare type OptionsFunction<TArgs> = (yargs: Argv) => Argv<TArgs>;
|
|
5
|
+
export declare type ArgsFromOptions<TOptionsFunction extends OptionsFunction<any>> = TOptionsFunction extends OptionsFunction<infer U> ? Args<U> : never;
|
|
6
|
+
export declare type Args<TArgs> = {
|
|
7
|
+
[key in keyof yargs.Arguments<TArgs> as key | yargs.CamelCaseKey<key>]: yargs.Arguments<TArgs>[key];
|
|
8
|
+
};
|
|
9
|
+
export declare function runCli<TArgs>(options: OptionsFunction<TArgs>, run: (args: Args<TArgs>) => Promise<void>): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,oBAAY,eAAe,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC;AAElE,oBAAY,eAAe,CAAC,gBAAgB,SAAS,eAAe,CAAC,GAAG,CAAC,IACvE,gBAAgB,SAAS,eAAe,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AAEtE,oBAAY,IAAI,CAAC,KAAK,IAAI;KACvB,GAAG,IAAI,MAAM,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAChC,GAAG,GACH,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;CAC1D,CAAC;AAEF,wBAAsB,MAAM,CAAC,KAAK,EAChC,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC,EAC/B,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,iBAe1C"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCli = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
6
|
+
const helpers_1 = require("yargs/helpers");
|
|
7
|
+
async function runCli(options, run) {
|
|
8
|
+
const argv = await options((0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)))
|
|
9
|
+
.strict()
|
|
10
|
+
.showHelpOnFail(false, "Specify --help for available options")
|
|
11
|
+
.epilogue(`\
|
|
12
|
+
Graphile's MIT-licensed Open Source Software is made possible thanks to support from our sponsors. To find out more about sponsorship, please visit:
|
|
13
|
+
|
|
14
|
+
💖 https://graphile.org/sponsor
|
|
15
|
+
|
|
16
|
+
Thank you for using our software.`)
|
|
17
|
+
.wrap(yargs_1.default.terminalWidth()).argv;
|
|
18
|
+
await run(argv);
|
|
19
|
+
}
|
|
20
|
+
exports.runCli = runCli;
|
|
21
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;AACA,0DAA0B;AAC1B,2CAAwC;AAejC,KAAK,UAAU,MAAM,CAC1B,OAA+B,EAC/B,GAAyC;IAEzC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;SACrD,MAAM,EAAE;SACR,cAAc,CAAC,KAAK,EAAE,sCAAsC,CAAC;SAC7D,QAAQ,CACP;;;;;kCAK4B,CAC7B;SACA,IAAI,CAAC,eAAK,CAAC,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC;IACpC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;AAClB,CAAC;AAjBD,wBAiBC"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PluginHook } from "./interfaces.js";
|
|
2
|
+
export declare type HookObject<T> = Record<keyof T, PluginHook<(...args: any[]) => any>>;
|
|
3
|
+
export declare class AsyncHooks<THooks extends HookObject<THooks>> {
|
|
4
|
+
callbacks: {
|
|
5
|
+
[key in keyof THooks]?: Array<THooks[keyof THooks] extends PluginHook<infer U> ? U : never>;
|
|
6
|
+
};
|
|
7
|
+
hook<THookName extends keyof THooks>(event: THookName, fn: THooks[THookName] extends PluginHook<infer U> ? U : never): void;
|
|
8
|
+
/**
|
|
9
|
+
* Hooks can _mutate_ the argument, they cannot return a replacement. This
|
|
10
|
+
* allows us to completely side-step the problem of recursive calls.
|
|
11
|
+
*/
|
|
12
|
+
process<THookName extends keyof THooks>(event: THookName, ...args: Parameters<THooks[THookName] extends PluginHook<infer U> ? U : never>): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function applyHooks<THooks extends HookObject<THooks>>(plugins: GraphileConfig.Plugin[], hooksRetriever: (plugin: GraphileConfig.Plugin) => Partial<THooks> | undefined, applyHookCallback: <THookName extends keyof THooks>(hookName: THookName, hookFn: THooks[THookName] extends PluginHook<infer U> ? U : never, plugin: GraphileConfig.Plugin) => void): void;
|
|
15
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,iBAAiB,CAAC;AAGpE,oBAAY,UAAU,CAAC,CAAC,IAAI,MAAM,CAChC,MAAM,CAAC,EACP,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CACpC,CAAC;AAEF,qBAAa,UAAU,CAAC,MAAM,SAAS,UAAU,CAAC,MAAM,CAAC;IACvD,SAAS,EAAE;SACR,GAAG,IAAI,MAAM,MAAM,CAAC,CAAC,EAAE,KAAK,CAC3B,MAAM,CAAC,MAAM,MAAM,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAC7D;KACF,CAAM;IAEP,IAAI,CAAC,SAAS,SAAS,MAAM,MAAM,EACjC,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,GAC5D,IAAI;IAKP;;;OAGG;IACG,OAAO,CAAC,SAAS,SAAS,MAAM,MAAM,EAC1C,KAAK,EAAE,SAAS,EAChB,GAAG,IAAI,EAAE,UAAU,CACjB,MAAM,CAAC,SAAS,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAC1D,GACA,OAAO,CAAC,IAAI,CAAC;CASjB;AAED,wBAAgB,UAAU,CAAC,MAAM,SAAS,UAAU,CAAC,MAAM,CAAC,EAC1D,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,EAChC,cAAc,EAAE,CACd,MAAM,EAAE,cAAc,CAAC,MAAM,KAC1B,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,EAChC,iBAAiB,EAAE,CAAC,SAAS,SAAS,MAAM,MAAM,EAChD,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,EACjE,MAAM,EAAE,cAAc,CAAC,MAAM,KAC1B,IAAI,GACR,IAAI,CAwEN"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyHooks = exports.AsyncHooks = void 0;
|
|
4
|
+
const sort_js_1 = require("./sort.js");
|
|
5
|
+
class AsyncHooks {
|
|
6
|
+
callbacks = {};
|
|
7
|
+
hook(event, fn) {
|
|
8
|
+
this.callbacks[event] = this.callbacks[event] || [];
|
|
9
|
+
this.callbacks[event].push(fn);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hooks can _mutate_ the argument, they cannot return a replacement. This
|
|
13
|
+
* allows us to completely side-step the problem of recursive calls.
|
|
14
|
+
*/
|
|
15
|
+
async process(event, ...args) {
|
|
16
|
+
const [arg, ...rest] = args;
|
|
17
|
+
const callbacks = this.callbacks[event];
|
|
18
|
+
if (callbacks) {
|
|
19
|
+
for (const callback of callbacks) {
|
|
20
|
+
await callback(arg, ...rest);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.AsyncHooks = AsyncHooks;
|
|
26
|
+
function applyHooks(plugins, hooksRetriever, applyHookCallback) {
|
|
27
|
+
// Normalize all the hooks and gather them into collections
|
|
28
|
+
const allHooks = Object.create(null);
|
|
29
|
+
let uid = 0;
|
|
30
|
+
for (const plugin of plugins) {
|
|
31
|
+
const hooks = hooksRetriever(plugin);
|
|
32
|
+
if (!hooks) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const keys = Object.keys(hooks);
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
const hookSpecRaw = hooks[key];
|
|
38
|
+
if (!hookSpecRaw) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
// TypeScript nonsense
|
|
42
|
+
const isPluginHookObject = (v) => typeof v !== "function";
|
|
43
|
+
const isPluginHookFunction = (v) => typeof v === "function";
|
|
44
|
+
const callback = (isPluginHookFunction(hookSpecRaw) ? hookSpecRaw : hookSpecRaw.callback);
|
|
45
|
+
const { provides, before, after } = isPluginHookObject(hookSpecRaw)
|
|
46
|
+
? hookSpecRaw
|
|
47
|
+
: {};
|
|
48
|
+
if (!allHooks[key]) {
|
|
49
|
+
allHooks[key] = [];
|
|
50
|
+
}
|
|
51
|
+
// We need to give each hook a unique ID
|
|
52
|
+
const id = String(uid++);
|
|
53
|
+
allHooks[key].push({
|
|
54
|
+
id,
|
|
55
|
+
plugin,
|
|
56
|
+
callback,
|
|
57
|
+
provides: [...(provides || []), id],
|
|
58
|
+
before: before || [],
|
|
59
|
+
after: after || [],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Sort the collections according to provides, before and after.
|
|
64
|
+
for (const hookName in allHooks) {
|
|
65
|
+
const hooks = allHooks[hookName];
|
|
66
|
+
if (!hooks) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const final = (0, sort_js_1.sortWithBeforeAfterProvides)(hooks, "id");
|
|
70
|
+
// Finally we can register the hooks
|
|
71
|
+
for (const hook of final) {
|
|
72
|
+
applyHookCallback(hookName, hook.callback, hook.plugin);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.applyHooks = applyHooks;
|
|
77
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AACA,uCAAwD;AAOxD,MAAa,UAAU;IACrB,SAAS,GAIL,EAAE,CAAC;IAEP,IAAI,CACF,KAAgB,EAChB,EAA6D;QAE7D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACpD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CACX,KAAgB,EAChB,GAAG,IAEF;QAED,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,SAAS,EAAE;YACb,KAAK,MAAM,QAAQ,IAAI,SAAU,EAAE;gBACjC,MAAM,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;aAC9B;SACF;IACH,CAAC;CACF;AAjCD,gCAiCC;AAED,SAAgB,UAAU,CACxB,OAAgC,EAChC,cAEgC,EAChC,iBAIS;IAUT,2DAA2D;IAC3D,MAAM,QAAQ,GAEV,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;Q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AAgE;IAChE,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE;QAC/B,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAA+B,CAAC;QAC/D,IAAI,CAAC,KAAK,EAAE;YACV,SAAS;SACV;QAED,MAAM,KAAK,GAAG,IAAA,qCAA2B,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEvD,oCAAoC;QACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;SACzD;KACF;AACH,CAAC;AAlFD,gCAkFC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "./interfaces.js";
|
|
2
|
+
export { GraphileConfig };
|
|
3
|
+
export { applyHooks, AsyncHooks, HookObject } from "./hooks.js";
|
|
4
|
+
export type { PluginHook, PluginHookObject } from "./interfaces.js";
|
|
5
|
+
export { resolvePresets } from "./resolvePresets.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAEzB,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePresets = exports.AsyncHooks = exports.applyHooks = void 0;
|
|
4
|
+
require("./interfaces.js");
|
|
5
|
+
var hooks_js_1 = require("./hooks.js");
|
|
6
|
+
Object.defineProperty(exports, "applyHooks", { enumerable: true, get: function () { return hooks_js_1.applyHooks; } });
|
|
7
|
+
Object.defineProperty(exports, "AsyncHooks", { enumerable: true, get: function () { return hooks_js_1.AsyncHooks; } });
|
|
8
|
+
var resolvePresets_js_1 = require("./resolvePresets.js");
|
|
9
|
+
Object.defineProperty(exports, "resolvePresets", { enumerable: true, get: function () { return resolvePresets_js_1.resolvePresets; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAIzB,uCAAgE;AAAvD,sGAAA,UAAU,OAAA;AAAE,sGAAA,UAAU,OAAA;AAE/B,yDAAqD;AAA5C,mHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace GraphileConfig {
|
|
3
|
+
interface Plugin {
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
experimental?: boolean;
|
|
7
|
+
description?: string;
|
|
8
|
+
provides?: string[];
|
|
9
|
+
after?: string[];
|
|
10
|
+
before?: string[];
|
|
11
|
+
}
|
|
12
|
+
interface Preset {
|
|
13
|
+
extends?: ReadonlyArray<Preset>;
|
|
14
|
+
plugins?: Plugin[];
|
|
15
|
+
disablePlugins?: ReadonlyArray<string>;
|
|
16
|
+
}
|
|
17
|
+
interface ResolvedPreset extends Preset {
|
|
18
|
+
extends?: ReadonlyArray<never>;
|
|
19
|
+
plugins?: Plugin[];
|
|
20
|
+
disablePlugins?: ReadonlyArray<string>;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export declare type PluginHookObject<T extends (...args: any[]) => any> = {
|
|
25
|
+
provides?: string[];
|
|
26
|
+
before?: string[];
|
|
27
|
+
after?: string[];
|
|
28
|
+
callback: T;
|
|
29
|
+
};
|
|
30
|
+
export declare type PluginHook<T extends (...args: any[]) => any> = T | PluginHookObject<T>;
|
|
31
|
+
export declare type PluginHookCallback<T extends PluginHook<(...args: any[]) => any>> = T extends PluginHook<infer U> ? U : never;
|
|
32
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,cAAc,CAAC;QACvB,UAAU,MAAM;YACd,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,YAAY,CAAC,EAAE,OAAO,CAAC;YACvB,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;YACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;YACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;SACnB;QAED,UAAU,MAAM;YACd,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;YAChC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;YACnB,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;SAGxC;QAED,UAAU,cAAe,SAAQ,MAAM;YAErC,OAAO,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;YAC/B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;YACnB,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;SACxC;KACF;CACF;AAED,oBAAY,gBAAgB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI;IAChE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,oBAAY,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IACpD,CAAC,GACD,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAExB,oBAAY,kBAAkB,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,IAC1E,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../src/loadConfig.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AA6CzB,wBAAsB,UAAU,CAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GACzB,OAAO,CAAC,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CA2CvC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadConfig = void 0;
|
|
4
|
+
require("./interfaces.js");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const interpret_1 = require("interpret");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const extensions = Object.keys(interpret_1.jsVariants);
|
|
9
|
+
async function exists(filePath) {
|
|
10
|
+
try {
|
|
11
|
+
await (0, promises_1.access)(filePath);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
// TODO: check the error code
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function registerLoader(loader) {
|
|
20
|
+
if (loader === null) {
|
|
21
|
+
// noop
|
|
22
|
+
}
|
|
23
|
+
else if (Array.isArray(loader)) {
|
|
24
|
+
let firstError;
|
|
25
|
+
for (const entry of loader) {
|
|
26
|
+
try {
|
|
27
|
+
await registerLoader(entry);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (!firstError) {
|
|
32
|
+
firstError = e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw firstError ?? new Error(`Empty array handler`);
|
|
37
|
+
}
|
|
38
|
+
else if (typeof loader === "string") {
|
|
39
|
+
require(loader);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof loader === "object" && loader != null) {
|
|
42
|
+
const loaderModule = require(loader.module);
|
|
43
|
+
loader.register(loaderModule);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error("Unsupported loader");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function loadConfig(configPath) {
|
|
50
|
+
if (configPath != null) {
|
|
51
|
+
// Explicitly load the file the user has indicated
|
|
52
|
+
const resolvedPath = (0, path_1.resolve)(process.cwd(), configPath);
|
|
53
|
+
// First try one of the supported loaders
|
|
54
|
+
for (const extension of extensions) {
|
|
55
|
+
if (resolvedPath.endsWith(extension)) {
|
|
56
|
+
registerLoader(interpret_1.jsVariants[extension]);
|
|
57
|
+
try {
|
|
58
|
+
return require(resolvedPath);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* continue to the next one */
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Fallback to direct import
|
|
66
|
+
return (await import(resolvedPath)).default;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// There's no config path; look for a `graphile.config.*`
|
|
70
|
+
const basePath = (0, path_1.resolve)(process.cwd(), "graphile.config");
|
|
71
|
+
for (const extension of extensions) {
|
|
72
|
+
const resolvedPath = basePath + extension;
|
|
73
|
+
if (await exists(resolvedPath)) {
|
|
74
|
+
registerLoader(interpret_1.jsVariants[extension]);
|
|
75
|
+
try {
|
|
76
|
+
return require(resolvedPath);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
if (e.code === "ERR_REQUIRE_ESM") {
|
|
80
|
+
return (await import(resolvedPath)).default;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// No config found
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
exports.loadConfig = loadConfig;
|
|
93
|
+
//# sourceMappingURL=loadConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadConfig.js","sourceRoot":"","sources":["../src/loadConfig.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAEzB,0CAAqC;AAErC,yCAAuC;AACvC,+BAA+B;AAE/B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,sBAAU,CAAC,CAAC;AAE3C,KAAK,UAAU,MAAM,CAAC,QAAgB;IACpC,IAAI;QACF,MAAM,IAAA,iBAAM,EAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,6BAA6B;QAC7B,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,MAAwB;IACpD,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,OAAO;KACR;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAChC,IAAI,UAAU,CAAC;QACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,IAAI;gBACF,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;gBAC5B,OAAO;aACR;YAAC,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,UAAU,EAAE;oBACf,UAAU,GAAG,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AC,YAAY,CAAC,EAAE;gBAC9B,cAAc,CAAC,sBAAU,CAAC,SAAS,CAAC,CAAC,CAAC;gBACtC,IAAI;oBACF,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;iBAC9B;gBAAC,OAAO,CAAC,EAAE;oBACV,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB,EAAE;wBAChC,OAAO,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC;qBAC7C;yBAAM;wBACL,MAAM,CAAC,CAAC;qBACT;iBACF;aACF;SACF;KACF;IAED,kBAAkB;IAClB,OAAO,IAAI,CAAC;AACd,CAAC;AA7CD,gCA6CC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./interfaces.js";
|
|
2
|
+
/**
|
|
3
|
+
* Given a list of presets, resolves the presets and returns the resulting
|
|
4
|
+
* ResolvedPreset (which does not have any `extends`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolvePresets(presets: ReadonlyArray<GraphileConfig.Preset>): GraphileConfig.ResolvedPreset;
|
|
7
|
+
//# sourceMappingURL=resolvePresets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePresets.d.ts","sourceRoot":"","sources":["../src/resolvePresets.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAoBzB;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC,GAC5C,cAAc,CAAC,cAAc,CAsB/B"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePresets = void 0;
|
|
4
|
+
require("./interfaces.js");
|
|
5
|
+
const sort_js_1 = require("./sort.js");
|
|
6
|
+
function inspect(a) {
|
|
7
|
+
// TODO: if node, use util.inspect
|
|
8
|
+
return Array.isArray(a) ||
|
|
9
|
+
!a ||
|
|
10
|
+
Object.getPrototypeOf(a) === null ||
|
|
11
|
+
Object.getPrototypeOf(a) === Object.prototype
|
|
12
|
+
? JSON.stringify(a)
|
|
13
|
+
: String(a);
|
|
14
|
+
}
|
|
15
|
+
function isResolvedPreset(preset) {
|
|
16
|
+
return (preset.plugins && preset.extends?.length === 0) || false;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Given a list of presets, resolves the presets and returns the resulting
|
|
20
|
+
* ResolvedPreset (which does not have any `extends`).
|
|
21
|
+
*/
|
|
22
|
+
function resolvePresets(presets) {
|
|
23
|
+
if (presets.length === 1) {
|
|
24
|
+
// Maybe it's already resolved?
|
|
25
|
+
const preset = presets[0];
|
|
26
|
+
if (preset && isResolvedPreset(preset)) {
|
|
27
|
+
return preset;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const finalPreset = blankResolvedPreset();
|
|
31
|
+
for (const preset of presets) {
|
|
32
|
+
const resolvedPreset = resolvePreset(preset);
|
|
33
|
+
mergePreset(finalPreset, resolvedPreset);
|
|
34
|
+
}
|
|
35
|
+
if (finalPreset.plugins) {
|
|
36
|
+
finalPreset.plugins = (0, sort_js_1.sortWithBeforeAfterProvides)(finalPreset.plugins, "name");
|
|
37
|
+
}
|
|
38
|
+
return finalPreset;
|
|
39
|
+
}
|
|
40
|
+
exports.resolvePresets = resolvePresets;
|
|
41
|
+
function isGraphileConfigPreset(foo) {
|
|
42
|
+
if (typeof foo !== "object" || foo === null)
|
|
43
|
+
return false;
|
|
44
|
+
// Check regular prototype
|
|
45
|
+
const prototype = Object.getPrototypeOf(foo);
|
|
46
|
+
if (prototype === null || prototype === Object.prototype) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
// Heavier check, to allow for Jest/VM complexity (where `Object` differs)
|
|
50
|
+
if (String(foo) === "[object Object]") {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
function assertPlugin(plugin) {
|
|
56
|
+
if (typeof plugin !== "object" || plugin == null) {
|
|
57
|
+
throw new Error(`Expected plugin, but found '${inspect(plugin)}'`);
|
|
58
|
+
}
|
|
59
|
+
const proto = Object.getPrototypeOf(plugin);
|
|
60
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
61
|
+
throw new Error(`Expected plugin to be a plain object, but found '${inspect(plugin)}'`);
|
|
62
|
+
}
|
|
63
|
+
if (typeof plugin.name !== "string") {
|
|
64
|
+
throw new Error(`Expected plugin to have a string 'name'; found ${inspect(plugin.name)} (${inspect(plugin)})`);
|
|
65
|
+
}
|
|
66
|
+
if (plugin.version != null && typeof plugin.version !== "string") {
|
|
67
|
+
throw new Error(`Expected plugin '${plugin.name}' to have a string 'version'; found ${inspect(plugin.version)}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Turns a preset into a resolved preset (i.e. resolves all its `extends`).
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
function resolvePreset(preset) {
|
|
76
|
+
if (!isGraphileConfigPreset(preset)) {
|
|
77
|
+
throw new Error(`Expected a GraphileConfig preset (a plain JS object), but found '${inspect(preset)}'`);
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const { extends: presets = [] } = preset;
|
|
81
|
+
const basePreset = resolvePresets(presets);
|
|
82
|
+
mergePreset(basePreset, preset);
|
|
83
|
+
const disabled = basePreset.disablePlugins;
|
|
84
|
+
if (disabled) {
|
|
85
|
+
const plugins = new Set(basePreset.plugins);
|
|
86
|
+
const remaining = new Set(disabled);
|
|
87
|
+
for (const plugin of plugins) {
|
|
88
|
+
assertPlugin(plugin);
|
|
89
|
+
if (remaining.has(plugin.name)) {
|
|
90
|
+
remaining.delete(plugin.name);
|
|
91
|
+
plugins.delete(plugin);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/*
|
|
95
|
+
|
|
96
|
+
TODO: we need an alert like this, but only at the very top level.
|
|
97
|
+
The easiest way to check is to just see if `disablePlugins` has length.
|
|
98
|
+
|
|
99
|
+
if (remaining.size > 0) {
|
|
100
|
+
console.warn(
|
|
101
|
+
`Attempted to 'disablePlugins', but the following plugin(s) weren't found: '${[
|
|
102
|
+
...remaining,
|
|
103
|
+
].join("', '")}' (known: ${[...plugins].map((p) => p.name)})`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
*/
|
|
107
|
+
basePreset.plugins = [...plugins];
|
|
108
|
+
basePreset.disablePlugins = [...remaining];
|
|
109
|
+
}
|
|
110
|
+
return basePreset;
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
throw new Error(`Error occurred when resolving preset: ${e}\nPreset: ${inspect(preset)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Merges `sourcePreset` into existing resolved preset `targetPreset`, ignoring
|
|
118
|
+
* any `extends` on the `sourcePreset`.
|
|
119
|
+
*
|
|
120
|
+
* Note this function uses mutation for performance reasons.
|
|
121
|
+
*
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
function mergePreset(targetPreset, sourcePreset) {
|
|
125
|
+
if (targetPreset.extends != null && targetPreset.extends.length !== 0) {
|
|
126
|
+
throw new Error("First argument to mergePreset must be a resolved preset");
|
|
127
|
+
}
|
|
128
|
+
const plugins = new Set([
|
|
129
|
+
...(targetPreset.plugins || []),
|
|
130
|
+
...(sourcePreset.plugins || []),
|
|
131
|
+
]);
|
|
132
|
+
targetPreset.plugins = [...plugins];
|
|
133
|
+
if (sourcePreset.disablePlugins) {
|
|
134
|
+
targetPreset.disablePlugins = [
|
|
135
|
+
...new Set([
|
|
136
|
+
...(targetPreset.disablePlugins ?? []),
|
|
137
|
+
...(sourcePreset.disablePlugins ?? []),
|
|
138
|
+
]),
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
const targetScopes = Object.keys(targetPreset).filter(isScopeKeyForPreset);
|
|
142
|
+
const sourceScopes = Object.keys(sourcePreset).filter(isScopeKeyForPreset);
|
|
143
|
+
const scopes = [...new Set([...targetScopes, ...sourceScopes])];
|
|
144
|
+
for (const scope of scopes) {
|
|
145
|
+
const targetScope = targetPreset[scope];
|
|
146
|
+
const sourceScope = sourcePreset[scope];
|
|
147
|
+
if (targetScope && sourceScope) {
|
|
148
|
+
targetPreset[scope] = Object.assign({}, targetScope, sourceScope);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
targetPreset[scope] = targetScope || sourceScope;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function blankResolvedPreset() {
|
|
156
|
+
return {
|
|
157
|
+
extends: [],
|
|
158
|
+
plugins: [],
|
|
159
|
+
disablePlugins: [],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Scope keys are all the keys except for the ones explicitly defined in the
|
|
164
|
+
* Preset type (before declaration merging).
|
|
165
|
+
*/
|
|
166
|
+
function isScopeKeyForPreset(key) {
|
|
167
|
+
return key !== "extends" && key !== "plugins" && key !== "disablePlugins";
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=resolvePresets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePresets.js","sourceRoot":"","sources":["../src/resolvePresets.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAEzB,uCAAwD;AAExD,SAAS,OAAO,CAAC,CAAM;IACrB,kCAAkC;IAClC,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI;QACjC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,SAAS;QAC7C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QACnB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAChB,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vides<TIdKey extends string, TSortable extends {
|
|
2
|
+
before?: string[];
|
|
3
|
+
after?: string[];
|
|
4
|
+
provides?: string[];
|
|
5
|
+
} & {
|
|
6
|
+
[id in TIdKey]: string;
|
|
7
|
+
}>(rawList: TSortable[], idKey: TIdKey): TSortable[];
|
|
8
|
+
//# sourceMappingURL=sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":"AAAA,wBAAgB,2BAA2B,CACzC,MAAM,SAAS,MAAM,EACrB,SAAS,SAAS;IAChB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,GAAG;KACD,EAAE,IAAI,MAAM,GAAG,MAAM;CACvB,EACD,OAAO,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAiHlD"}
|
package/dist/sort.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortWithBeforeAfterProvides = void 0;
|
|
4
|
+
function sortWithBeforeAfterProvides(rawList, idKey) {
|
|
5
|
+
const list = rawList.map((listEntry) => {
|
|
6
|
+
if (!listEntry.after) {
|
|
7
|
+
listEntry.after = [];
|
|
8
|
+
}
|
|
9
|
+
if (!listEntry.provides) {
|
|
10
|
+
listEntry.provides = [];
|
|
11
|
+
}
|
|
12
|
+
if (!listEntry.provides.includes(listEntry[idKey])) {
|
|
13
|
+
listEntry.provides.push(listEntry[idKey]);
|
|
14
|
+
}
|
|
15
|
+
return listEntry;
|
|
16
|
+
});
|
|
17
|
+
// "before" and "after" are very similar, lets simplify them into one
|
|
18
|
+
// concept by converting all the "befores" into "afters" on their targets.
|
|
19
|
+
for (const listEntry of list) {
|
|
20
|
+
const { [idKey]: id, before = [] } = listEntry;
|
|
21
|
+
if (before.length) {
|
|
22
|
+
const previousBefore = before.splice(0, before.length);
|
|
23
|
+
for (const otherListEntry of list) {
|
|
24
|
+
if (otherListEntry !== listEntry &&
|
|
25
|
+
previousBefore.some((beforeValue) => otherListEntry.provides.includes(beforeValue))) {
|
|
26
|
+
if (!otherListEntry.after) {
|
|
27
|
+
otherListEntry.after = [id];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
otherListEntry.after.push(id);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Now lets figure out all the possible provides values:
|
|
37
|
+
const providers = Object.create(null);
|
|
38
|
+
for (const listEntry of list) {
|
|
39
|
+
const { provides } = listEntry;
|
|
40
|
+
for (const provide of provides) {
|
|
41
|
+
if (!providers[provide]) {
|
|
42
|
+
providers[provide] = [];
|
|
43
|
+
}
|
|
44
|
+
providers[provide].push(listEntry);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// And ignore any "afters" with no providers:
|
|
48
|
+
const validProviders = Object.keys(providers);
|
|
49
|
+
for (const listEntry of list) {
|
|
50
|
+
listEntry.after = listEntry.after.filter((afterValue) => validProviders.includes(afterValue));
|
|
51
|
+
}
|
|
52
|
+
const final = [];
|
|
53
|
+
const remaining = [...list];
|
|
54
|
+
// Now we can iteratively add items following the rule that there must be
|
|
55
|
+
// no pending items that "provides" anything that the listEntry must come
|
|
56
|
+
// "after".
|
|
57
|
+
for (let loops = 0; loops < 10000; loops++) {
|
|
58
|
+
let changes = 0;
|
|
59
|
+
if (remaining.length === 0) {
|
|
60
|
+
// We're done!
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
for (let i = 0; i < remaining.length; i++) {
|
|
64
|
+
const listEntry = remaining[i];
|
|
65
|
+
if (!listEntry) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const dependsOnRemaining = remaining.some((otherListEntry) => otherListEntry !== listEntry &&
|
|
69
|
+
otherListEntry.provides.some((otherHookProvide) => listEntry.after.includes(otherHookProvide)));
|
|
70
|
+
if (!dependsOnRemaining) {
|
|
71
|
+
changes++;
|
|
72
|
+
remaining.splice(i, 1);
|
|
73
|
+
final.push(listEntry);
|
|
74
|
+
i--;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (changes === 0) {
|
|
78
|
+
throw new Error(`Infinite loop in dependencies detected; remaining items:\n ${remaining
|
|
79
|
+
.map((r) => `${r[idKey]} (after: ${r.after}; provides: ${r.provides})`)
|
|
80
|
+
.join("\n ")}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (final.length !== list.length) {
|
|
84
|
+
throw new Error(`Expected the same number of list entries after sorting (${final.length} != ${list.length})`);
|
|
85
|
+
}
|
|
86
|
+
return final;
|
|
87
|
+
}
|
|
88
|
+
exports.sortWithBeforeAfterProvides = sortWithBeforeAfterProvides;
|
|
89
|
+
//# sourceMappingURL=sort.js.map
|
package/dist/sort.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.js","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":";;;AAAA,SAAgB,2BAA2B,CASzC,OAAoB,EAAE,KAAa;IACnC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QACrC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;YACpB,SAAS,CAAC,KAAK,GAAG,EAAE,CAAC;SACtB;QACD,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YACvB,SAAS,CAAC,QAAQ,GAAG,EAAE,CAAC;SACzB;QACD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE;YAClD,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAA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K,CACb,+DAA+D,SAAS;iBACrE,GAAG,CACF,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,QAAQ,GAAG,CAClE;iBACA,IAAI,CAAC,MAAM,CAAC,EAAE,CAClB,CAAC;SACH;KACF;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE;QAChC,MAAM,IAAI,KAAK,CACb,2DAA2D,KAAK,CAAC,MAAM,OAAO,IAAI,CAAC,MAAM,GAAG,CAC7F,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA1HD,kEA0HC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "graphile-config",
|
|
3
|
+
"version": "0.0.1-0.0",
|
|
4
|
+
"description": "Standard plugin interface and helpers to be used across the Graphile stack.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./load": {
|
|
14
|
+
"types": "./dist/loadConfig.d.ts",
|
|
15
|
+
"default": "./dist/loadConfig.js"
|
|
16
|
+
},
|
|
17
|
+
"./cli": {
|
|
18
|
+
"types": "./dist/cli.d.ts",
|
|
19
|
+
"default": "./dist/cli.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prepack": "tsc -b"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/graphile/heart.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"graphile",
|
|
31
|
+
"plugin",
|
|
32
|
+
"graphite"
|
|
33
|
+
],
|
|
34
|
+
"author": "Benjie Gillam <code@benjiegillam.com>",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/graphile/heart/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://graphile.org/graphile-build/",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@types/interpret": "^1.1.1",
|
|
42
|
+
"@types/node": "^16.11.15",
|
|
43
|
+
"@types/semver": "^7.3.9",
|
|
44
|
+
"chalk": "^4.1.2",
|
|
45
|
+
"debug": "^4.3.3",
|
|
46
|
+
"interpret": "^2.2.0",
|
|
47
|
+
"semver": "^7.3.5",
|
|
48
|
+
"tslib": "^2.4.0"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=16"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist"
|
|
55
|
+
],
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/debug": "^4.1.7",
|
|
58
|
+
"@types/jest": "^27.5.1",
|
|
59
|
+
"jest": "^28.1.0",
|
|
60
|
+
"ts-node": "^10.9.1",
|
|
61
|
+
"typescript": "^4.8.1-rc"
|
|
62
|
+
}
|
|
63
|
+
}
|