graphile-config
Advanced tools
Comparing version 0.0.1-beta.11 to 0.0.1-beta.12
# graphile-config | ||
## 0.0.1-beta.12 | ||
### Patch Changes | ||
- [#2240](https://github.com/graphile/crystal/pull/2240) | ||
[`d13b76f0f`](https://github.com/graphile/crystal/commit/d13b76f0fef2a58466ecb44880af62d25910e83e) | ||
Thanks [@benjie](https://github.com/benjie)! - Adds | ||
`MiddlewareHandlers<TActivities>` type to help with adding middleware to | ||
configs | ||
- [#2253](https://github.com/graphile/crystal/pull/2253) | ||
[`b167bd849`](https://github.com/graphile/crystal/commit/b167bd8499be5866b71bac6594d55bd768fda1d0) | ||
Thanks [@benjie](https://github.com/benjie)! - 🚨 `{}` is no longer a valid | ||
`GraphileConfig.ResolvedPreset`; use `resolvePreset({})` | ||
Also: adds `resolvePreset(preset)` and deprecates `resolvePresets(presets)`. | ||
- [#2250](https://github.com/graphile/crystal/pull/2250) | ||
[`6a13ecbd4`](https://github.com/graphile/crystal/commit/6a13ecbd45534c39c846c1d8bc58242108426dd1) | ||
Thanks [@benjie](https://github.com/benjie)! - Add support for 'preset.lib' | ||
which can be used to store global module references to help avoid the dual | ||
package hazard. | ||
## 0.0.1-beta.11 | ||
@@ -4,0 +27,0 @@ |
@@ -6,8 +6,11 @@ import "./interfaces.js"; | ||
export type { CallbackDescriptor, CallbackOrDescriptor, FunctionalityObject, } from "./interfaces.js"; | ||
export type { MiddlewareNext } from "./middleware.js"; | ||
export type { MiddlewareHandlers, MiddlewareNext } from "./middleware.js"; | ||
export { Middleware } from "./middleware.js"; | ||
export { isResolvedPreset, resolvePresets } from "./resolvePresets.js"; | ||
export { isResolvedPreset, resolvePreset, resolvePresets, } from "./resolvePresets.js"; | ||
export declare function sortedPlugins(plugins: GraphileConfig.Plugin[] | undefined): GraphileConfig.Plugin[]; | ||
declare global { | ||
namespace GraphileConfig { | ||
interface Lib { | ||
versions: Record<string, string | undefined>; | ||
} | ||
/** | ||
@@ -45,2 +48,3 @@ * Expand this through declaration merging to get TypeScript | ||
disablePlugins?: ReadonlyArray<keyof GraphileConfig.Plugins>; | ||
lib?: Partial<GraphileConfig.Lib>; | ||
appendPlugins?: never; | ||
@@ -50,6 +54,12 @@ prependPlugins?: never; | ||
} | ||
/** | ||
* The result of `resolvePreset(preset)` on a preset - compatible with | ||
* `Preset` but guaranteed to not extend from other presets (and a few | ||
* other assertions). | ||
*/ | ||
interface ResolvedPreset extends Preset { | ||
extends?: ReadonlyArray<never>; | ||
plugins?: Plugin[]; | ||
disablePlugins?: ReadonlyArray<keyof GraphileConfig.Plugins>; | ||
extends?: never; | ||
plugins: Plugin[]; | ||
disablePlugins: ReadonlyArray<keyof GraphileConfig.Plugins>; | ||
lib: GraphileConfig.Lib; | ||
} | ||
@@ -56,0 +66,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sortedPlugins = exports.resolvePresets = exports.isResolvedPreset = exports.Middleware = exports.AsyncHooks = exports.applyHooks = exports.orderedApply = void 0; | ||
exports.sortedPlugins = exports.resolvePresets = exports.resolvePreset = exports.isResolvedPreset = exports.Middleware = exports.AsyncHooks = exports.applyHooks = exports.orderedApply = void 0; | ||
require("./interfaces.js"); | ||
@@ -15,2 +15,3 @@ const sort_js_1 = require("./sort.js"); | ||
Object.defineProperty(exports, "isResolvedPreset", { enumerable: true, get: function () { return resolvePresets_js_1.isResolvedPreset; } }); | ||
Object.defineProperty(exports, "resolvePreset", { enumerable: true, get: function () { return resolvePresets_js_1.resolvePreset; } }); | ||
Object.defineProperty(exports, "resolvePresets", { enumerable: true, get: function () { return resolvePresets_js_1.resolvePresets; } }); | ||
@@ -17,0 +18,0 @@ function sortedPlugins(plugins) { |
@@ -17,3 +17,6 @@ import type { CallbackOrDescriptor, FunctionalityObject } from "./interfaces.js"; | ||
} | ||
export type MiddlewareHandlers<TActivities extends FunctionalityObject<TActivities>> = { | ||
[key in keyof TActivities]?: CallbackOrDescriptor<TActivities[key] extends (...args: infer UArgs) => infer UResult ? (next: MiddlewareNext<UResult>, ...args: UArgs) => UResult : never>; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=middleware.d.ts.map |
import "./interfaces.js"; | ||
export declare function isResolvedPreset(preset: GraphileConfig.Preset): preset is GraphileConfig.ResolvedPreset; | ||
/** @deprecated Use `resolvePreset({ extends: presets })` instead */ | ||
export declare function resolvePresets(presets: ReadonlyArray<GraphileConfig.Preset>): GraphileConfig.ResolvedPreset; | ||
/** | ||
* Given a list of presets, resolves the presets and returns the resulting | ||
* ResolvedPreset (which does not have any `extends`). | ||
* Given a preset, recursively resolves all the `extends` and returns the | ||
* resulting ResolvedPreset (which does not have any `extends`). | ||
*/ | ||
export declare function resolvePresets(presets: ReadonlyArray<GraphileConfig.Preset>): GraphileConfig.ResolvedPreset; | ||
export declare function resolvePreset(preset: GraphileConfig.Preset): GraphileConfig.ResolvedPreset; | ||
//# sourceMappingURL=resolvePresets.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolvePresets = exports.isResolvedPreset = void 0; | ||
exports.resolvePreset = exports.resolvePresets = exports.isResolvedPreset = void 0; | ||
require("./interfaces.js"); | ||
@@ -40,24 +40,32 @@ const sort_js_1 = require("./sort.js"); | ||
function isResolvedPreset(preset) { | ||
return ((preset.plugins && | ||
preset.extends?.length === 0 && | ||
(!preset.disablePlugins || | ||
!preset.plugins || | ||
!preset.plugins.some((p) => preset.disablePlugins.includes(p.name)))) || | ||
return ((preset.extends == null && | ||
preset.plugins && | ||
preset.disablePlugins && | ||
typeof preset.lib === "object" && | ||
preset.lib !== null && | ||
!preset.plugins.some((p) => preset.disablePlugins.includes(p.name))) || | ||
false); | ||
} | ||
exports.isResolvedPreset = isResolvedPreset; | ||
/** | ||
* Given a list of presets, resolves the presets and returns the resulting | ||
* ResolvedPreset (which does not have any `extends`). | ||
*/ | ||
/** @deprecated Use `resolvePreset({ extends: presets })` instead */ | ||
function resolvePresets(presets) { | ||
if (presets.length === 1) { | ||
// Maybe it's already resolved? | ||
const preset = presets[0]; | ||
if (preset && isResolvedPreset(preset)) { | ||
return preset; | ||
} | ||
return resolvePreset(presets[0]); | ||
} | ||
else { | ||
return resolvePreset({ extends: presets }); | ||
} | ||
} | ||
exports.resolvePresets = resolvePresets; | ||
/** | ||
* Given a preset, recursively resolves all the `extends` and returns the | ||
* resulting ResolvedPreset (which does not have any `extends`). | ||
*/ | ||
function resolvePreset(preset) { | ||
// Maybe it's already resolved? | ||
if (preset && isResolvedPreset(preset)) { | ||
return preset; | ||
} | ||
const seenPluginNames = new Set(); | ||
const resolvedPreset = resolvePresetsInternal(presets, seenPluginNames, 0); | ||
const resolvedPreset = resolvePresetsInternal([preset], seenPluginNames, 0); | ||
const disabledButNotSeen = resolvedPreset.disablePlugins?.filter((n) => !seenPluginNames.has(n)); | ||
@@ -71,3 +79,3 @@ if (disabledButNotSeen?.length) { | ||
} | ||
exports.resolvePresets = resolvePresets; | ||
exports.resolvePreset = resolvePreset; | ||
function resolvePresetsInternal(presets, seenPluginNames, depth) { | ||
@@ -195,3 +203,3 @@ const finalPreset = blankResolvedPreset(); | ||
} | ||
if (targetPreset.extends != null && targetPreset.extends.length !== 0) { | ||
if (targetPreset.extends != null) { | ||
throw new Error("First argument to mergePreset must be a resolved preset"); | ||
@@ -220,2 +228,33 @@ } | ||
targetPreset.plugins = [...plugins].filter((p) => !disablePlugins.includes(p.name)); | ||
if (sourcePreset.lib) { | ||
for (const key of Object.keys(sourcePreset.lib)) { | ||
const sourceValue = sourcePreset.lib[key]; | ||
if (!(key in targetPreset.lib)) { | ||
targetPreset.lib[key] = sourceValue; | ||
} | ||
else if (key === "versions") { | ||
if (sourceValue) { | ||
for (const versionKey of Object.keys(sourceValue)) { | ||
const { versions: targetVersions } = targetPreset.lib; | ||
const sourceVersion = sourceValue[versionKey]; | ||
if (targetVersions[versionKey] === sourceVersion) { | ||
// noop | ||
} | ||
else if (targetVersions[versionKey]) { | ||
throw new Error(`Preset attempted to register version '${sourceVersion}' of '${versionKey}', but version '${targetVersions[versionKey]}' is already registered`); | ||
} | ||
else { | ||
targetVersions[versionKey] = sourceVersion; | ||
} | ||
} | ||
} | ||
} | ||
else if (targetPreset.lib[key] === sourceValue) { | ||
// noop | ||
} | ||
else { | ||
throw new Error(`Two different presets defined lib '${key}' but they had different values:\n\n ${inspect(targetPreset.lib[key]).replace(/\n/g, "\n ")}\n\nvs\n\n ${inspect(sourceValue).replace(/\n/g, "\n ")}`); | ||
} | ||
} | ||
} | ||
const targetScopes = Object.keys(targetPreset).filter(isScopeKeyForPreset); | ||
@@ -232,8 +271,6 @@ const sourceScopes = Object.keys(sourcePreset).filter(isScopeKeyForPreset); | ||
else if (Array.isArray(sourceScope)) { | ||
targetPreset[scope] = | ||
sourceScope; | ||
targetPreset[scope] = sourceScope; | ||
} | ||
else { | ||
targetPreset[scope] = | ||
Object.assign(Object.create(null), targetScope, sourceScope); | ||
targetPreset[scope] = Object.assign(Object.create(null), targetScope, sourceScope); | ||
} | ||
@@ -243,3 +280,3 @@ } | ||
targetPreset[scope] = | ||
(targetScope || sourceScope); | ||
targetScope || sourceScope; | ||
} | ||
@@ -250,5 +287,5 @@ } | ||
return { | ||
extends: [], | ||
plugins: [], | ||
disablePlugins: [], | ||
lib: Object.create(null), | ||
}; | ||
@@ -261,4 +298,7 @@ } | ||
function isScopeKeyForPreset(key) { | ||
return key !== "extends" && key !== "plugins" && key !== "disablePlugins"; | ||
return (key !== "extends" && | ||
key !== "plugins" && | ||
key !== "disablePlugins" && | ||
key !== "lib"); | ||
} | ||
//# sourceMappingURL=resolvePresets.js.map |
{ | ||
"name": "graphile-config", | ||
"version": "0.0.1-beta.11", | ||
"version": "0.0.1-beta.12", | ||
"description": "Standard plugin interface and helpers to be used across the Graphile stack.", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94467
883