Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@typegraph/sdk

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typegraph/sdk - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

66

gen/interfaces/metatype-typegraph-core.d.ts

@@ -16,4 +16,6 @@ export namespace MetatypeTypegraphCore {

export function structb(data: TypeStruct, base: TypeBase): TypeId;
export function extendStruct(tpe: TypeId, props: [string, TypeId][]): TypeId;
export function getTypeRepr(id: TypeId): string;
export function funcb(data: TypeFunc): TypeId;
export function getTransformData(resolverInput: TypeId, transformTree: string): TransformData;
export function registerPolicy(pol: Policy): PolicyId;

@@ -26,2 +28,3 @@ export function withPolicy(typeId: TypeId, policyChain: PolicySpec[]): TypeId;

export function expose(fns: [string, TypeId][], defaultPolicy: PolicySpec[] | undefined): void;
export function setSeed(seed: number | undefined): void;
}

@@ -54,10 +57,22 @@ export interface Error {

}
/**
* # Variants
*
* ## `"simple"`
*
* ## `"resolve-artifacts"`
*/
export type TypegraphFinalizeMode = 'simple' | 'resolve-artifacts';
export interface MigrationAction {
create: boolean,
reset: boolean,
}
export interface MigrationConfig {
migrationDir?: string,
action: MigrationAction,
}
export interface ArtifactResolutionConfig {
dir?: string,
prismaMigration: MigrationConfig,
}
export type TypegraphFinalizeMode = TypegraphFinalizeModeSimple | TypegraphFinalizeModeResolveArtifacts;
export interface TypegraphFinalizeModeSimple {
tag: 'simple',
}
export interface TypegraphFinalizeModeResolveArtifacts {
tag: 'resolve-artifacts',
val: ArtifactResolutionConfig | undefined,
}
export type TypeId = number;

@@ -124,2 +139,31 @@ export interface TypeBase {

}
export type ValueSource = ValueSourceRaw | ValueSourceContext | ValueSourceSecret | ValueSourceParent | ValueSourceParam;
export interface ValueSourceRaw {
tag: 'raw',
val: string,
}
export interface ValueSourceContext {
tag: 'context',
val: string,
}
export interface ValueSourceSecret {
tag: 'secret',
val: string,
}
export interface ValueSourceParent {
tag: 'parent',
val: string,
}
export interface ValueSourceParam {
tag: 'param',
val: string,
}
export interface ParameterTransform {
resolverInput: TypeId,
transformTree: string,
}
export interface TransformData {
queryInput: TypeId,
parameterTransform: ParameterTransform,
}
export type PolicyId = number;

@@ -141,3 +185,6 @@ export interface PolicyPerEffect {

}
export type ContextCheck = ContextCheckValue | ContextCheckPattern;
export type ContextCheck = ContextCheckNotNull | ContextCheckValue | ContextCheckPattern;
export interface ContextCheckNotNull {
tag: 'not-null',
}
export interface ContextCheckValue {

@@ -155,2 +202,3 @@ tag: 'value',

inp: TypeId,
parameterTransform?: ParameterTransform,
out: TypeId,

@@ -157,0 +205,0 @@ mat: MaterializerId,

export namespace MetatypeTypegraphHost {
export function expandGlob(root: string, exclude: string[]): string[];
export function fileExists(path: string): boolean;
export function readFile(path: string): Uint8Array;
export function writeFile(path: string, data: Uint8Array): void;
export function getCwd(): string;
}

7

gen/interfaces/metatype-typegraph-utils.d.ts

@@ -10,3 +10,6 @@ export namespace MetatypeTypegraphUtils {

export function oauth2WithCustomProfiler(serviceName: string, scopes: string, profiler: TypeId): string;
export function genGqlquery(params: QueryBodyParams): string;
export function gqlDeployQuery(params: QueryDeployParams): string;
export function gqlRemoveQuery(tgName: string[]): string;
export function unpackTarb64(tarB64: string, dest: string): void;
export function removeInjections(typeId: TypeId): TypeId;
}

@@ -42,3 +45,3 @@ import type { Error } from '../interfaces/metatype-typegraph-core.js';

}
export interface QueryBodyParams {
export interface QueryDeployParams {
tg: string,

@@ -45,0 +48,0 @@ cliVersion: string,

export declare function expandGlob(root: string, exclude: Array<string>): Array<string>;
export declare function print(msg: string): void;
export declare function eprint(msg: string): void;
export declare function getCwd(): string;
export declare function fileExists(path: string): boolean;
export declare function readFile(path: string): Uint8Array;
export declare function writeFile(path: string, data: Uint8Array): void;
export declare function fileExists(filePath: string): boolean;
export declare function readFile(filePath: string): Uint8Array;
export declare function writeFile(filePath: string, data: Uint8Array): void;

@@ -38,2 +38,5 @@ // Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.

}
export function eprint(msg) {
console.error(msg);
}
export function getCwd() {

@@ -47,5 +50,5 @@ try {

}
export function fileExists(path) {
export function fileExists(filePath) {
try {
return fs.existsSync(path);
return fs.existsSync(filePath);
}

@@ -56,5 +59,5 @@ catch (err) {

}
export function readFile(path) {
export function readFile(filePath) {
try {
const buffer = fs.readFileSync(path, null);
const buffer = fs.readFileSync(filePath, null);
return new Uint8Array(buffer);

@@ -66,5 +69,9 @@ }

}
export function writeFile(path, data) {
export function writeFile(filePath, data) {
try {
void fs.writeFileSync(path, data);
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
void fs.writeFileSync(filePath, data, { flag: "w" });
}

@@ -71,0 +78,0 @@ catch (err) {

{
"name": "@typegraph/sdk",
"version": "0.3.4",
"version": "0.3.5",
"description": "Declarative API development platform. Build serverless backends with zero-trust and less code, no matter where and how your (legacy) systems are.",

@@ -5,0 +5,0 @@ "type": "module",

@@ -13,2 +13,3 @@ import { MaterializerId } from "./gen/interfaces/metatype-typegraph-core.js";

export default class Policy {
#private;
readonly _id: number;

@@ -18,3 +19,3 @@ readonly name: string;

static public(): Policy;
static context(key: string, check: string | RegExp): Policy;
static context(key: string, check?: string | RegExp | null): Policy;
static internal(): Policy;

@@ -21,0 +22,0 @@ static create(name: string, materializerId: MaterializerId): Policy;

// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _a, _Policy_serializeContext;
import { core } from "./wit.js";

@@ -9,3 +15,3 @@ export class PolicyPerEffectObject {

}
export default class Policy {
class Policy {
constructor(_id, name) {

@@ -17,16 +23,14 @@ this._id = _id;

const [id, name] = core.getPublicPolicy();
return new Policy(id, name);
return new _a(id, name);
}
static context(key, check) {
const [id, name] = core.registerContextPolicy(key, typeof check === "string"
? { tag: "value", val: check }
: { tag: "pattern", val: check.source });
return new Policy(id, name);
const [id, name] = core.registerContextPolicy(key, __classPrivateFieldGet(_a, _a, "m", _Policy_serializeContext).call(_a, check !== null && check !== void 0 ? check : null));
return new _a(id, name);
}
static internal() {
const [id, name] = core.getInternalPolicy();
return new Policy(id, name);
return new _a(id, name);
}
static create(name, materializerId) {
return new Policy(core.registerPolicy({ name, materializer: materializerId }), name);
return new _a(core.registerPolicy({ name, materializer: materializerId }), name);
}

@@ -37,1 +41,14 @@ static on(effects) {

}
_a = Policy, _Policy_serializeContext = function _Policy_serializeContext(check) {
if (check === null) {
return { tag: "not-null" };
}
if (typeof check === "string") {
return { tag: "value", val: check };
}
if (!(check instanceof RegExp)) {
throw new Error("Invalid context check: expected null, string, or RegExp");
}
return { tag: "pattern", val: check.source };
};
export default Policy;

@@ -22,5 +22,3 @@ import { Materializer, Runtime } from "../runtimes/mod.js";

constructor(options: S3RuntimeData);
presignGet(params: S3PresignGetParams): t.Func<{
[key: string]: t.Typedef;
}, t.Struct<{
presignGet(params: S3PresignGetParams): t.Func<t.Struct<{
path: {

@@ -58,2 +56,3 @@ readonly min?: number | undefined;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -66,2 +65,3 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -100,2 +100,3 @@ }>, {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -108,6 +109,5 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
}, S3PresignGetMat>;
presignPut(params: S3PresignPutParams): t.Func<{
[key: string]: t.Typedef;
}, t.Struct<{
presignPut(params: S3PresignPutParams): t.Func<t.Struct<{
length: {

@@ -146,2 +146,3 @@ readonly min?: number | undefined;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -154,2 +155,3 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -188,2 +190,3 @@ path: {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -196,2 +199,3 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -230,2 +234,3 @@ }>, {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -238,6 +243,5 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
}, S3PresignPutMat>;
list(bucket: string): t.Func<{
[key: string]: t.Typedef;
}, t.Struct<{
list(bucket: string): t.Func<t.Struct<{
path: {

@@ -261,2 +265,3 @@ readonly item?: number | undefined;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -295,2 +300,3 @@ }>, t.Struct<{

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -303,2 +309,3 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -336,2 +343,3 @@ prefix: {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -344,7 +352,6 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};
}>, S3ListMat>;
upload(bucket: string, overrideFileType?: t.Typedef): t.Func<{
[key: string]: t.Typedef;
}, t.Struct<{
upload(bucket: string, overrideFileType?: t.Typedef): t.Func<t.Struct<{
file: t.Typedef;

@@ -369,2 +376,3 @@ path: {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -398,2 +406,3 @@ }>, {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -406,6 +415,5 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
}, S3UploadMat>;
uploadAll(bucket: string, overrideFileType?: t.Typedef): t.Func<{
[key: string]: t.Typedef;
}, t.Struct<{
uploadAll(bucket: string, overrideFileType?: t.Typedef): t.Func<t.Struct<{
prefix: {

@@ -429,2 +437,3 @@ readonly item?: number | undefined;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -462,2 +471,3 @@ files: {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -470,2 +480,3 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -499,2 +510,3 @@ }>, {

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
};

@@ -507,4 +519,5 @@ withInjection(injection: string): any;

fromParent(value: import("../utils/type_utils.js").InjectionValue<string>): any;
fromRandom(): any;
}, S3UploadAllMat>;
}
export {};

@@ -14,104 +14,74 @@ import { Runtime } from "../runtimes/mod.js";

constructor(name: string, connectionStringSecret: string);
findUnique(model: string | Typedef): t.Func<{
findUnique(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
findMany(model: string | Typedef): t.Func<{
findMany(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
findFirst(model: string | Typedef): t.Func<{
findFirst(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
aggregate(model: string | Typedef): t.Func<{
aggregate(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
count(model: string | Typedef): t.Func<{
count(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
groupBy(model: string | Typedef): t.Func<{
groupBy(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
create(model: string | Typedef): t.Func<{
create(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
createMany(model: string | Typedef): t.Func<{
createMany(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
update(model: string | Typedef): t.Func<{
update(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
updateMany(model: string | Typedef): t.Func<{
updateMany(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
upsert(model: string | Typedef): t.Func<{
upsert(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
delete(model: string | Typedef): t.Func<{
delete(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
deleteMany(model: string | Typedef): t.Func<{
deleteMany(model: string | Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
execute(query: string, parameters: Typedef, effect: Effect): t.Func<{
execute(query: string, parameters: Typedef, effect: Effect): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
queryRaw(query: string, parameters: Typedef | null, output: Typedef): t.Func<{
queryRaw(query: string, parameters: Typedef | null, output: Typedef): t.Func<t.Struct<{
[key: string]: Typedef;
}, t.Struct<{
[key: string]: Typedef;
}>, Typedef, {

@@ -118,0 +88,0 @@ _id: number;

@@ -8,27 +8,19 @@ import { Runtime } from "../runtimes/mod.js";

constructor(name: string, host: string);
startWorkflow(workflowType: string, arg: Typedef): Func<{
startWorkflow(workflowType: string, arg: Typedef): Func<import("../types.js").Struct<{
[key: string]: Typedef;
}, import("../types.js").Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
signalWorkflow(signalName: string, arg: Typedef): Func<{
signalWorkflow(signalName: string, arg: Typedef): Func<import("../types.js").Struct<{
[key: string]: Typedef;
}, import("../types.js").Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
queryWorkflow(queryType: string, arg: Typedef): Func<{
queryWorkflow(queryType: string, arg: Typedef): Func<import("../types.js").Struct<{
[key: string]: Typedef;
}, import("../types.js").Struct<{
[key: string]: Typedef;
}>, Typedef, {
_id: number;
}>;
describeWorkflow(): Func<{
describeWorkflow(): Func<import("../types.js").Struct<{
[key: string]: Typedef;
}, import("../types.js").Struct<{
[key: string]: Typedef;
}>, Typedef, {

@@ -35,0 +27,0 @@ _id: number;

@@ -20,3 +20,3 @@ import * as t from "../types.js";

export interface DenoFunc {
code: string;
code: string | Function;
secrets?: Array<string>;

@@ -33,8 +33,6 @@ effect?: Effect;

constructor();
func<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, { code, secrets, effect }: DenoFunc): t.Func<P, I, O, FunMat>;
import<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, { name, module, effect, secrets }: DenoImport): t.Func<P, I, O, ImportMat>;
identity<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>>(inp: I): t.Func<P, I, I, PredefinedFuncMat>;
static<P extends t.Typedef>(out: P, value: any): t.Func<{
[key: string]: t.Typedef;
}, t.Struct<{}>, P, {
func<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, { code, secrets, effect }: DenoFunc): t.Func<I, O, FunMat>;
import<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, { name, module, effect, secrets }: DenoImport): t.Func<I, O, ImportMat>;
identity<I extends t.Typedef = t.Typedef>(inp: I): t.Func<I, t.Typedef, PredefinedFuncMat>;
static<P extends t.Typedef>(out: P, value: any): t.Func<t.Struct<{}>, P, {
_id: number;

@@ -41,0 +39,0 @@ }>;

// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import * as t from "../types.js";
import { runtimes } from "../wit.js";
import { runtimes, wit_utils } from "../wit.js";
import Policy from "../policy.js";
import { Runtime } from "./mod.js";
import { fx } from "../index.js";
function stringifyFn(code) {
if (typeof code == "function") {
const source = code.toString();
const namedFnMatch = source.match(/function\s*(\*?\s*[a-zA-Z0-9_]+)/);
if (namedFnMatch) {
const [, name] = namedFnMatch;
if (name.replace(/\s/g, "").startsWith("*")) {
throw new Error(`Generator function "${name}" not supported`);
}
if (/function\s[a-zA-Z0-9_]+\(\) { \[native code\] }/.test(source)) {
throw new Error(`"${name}" is not supported as it is a native function`);
}
}
return source;
}
return code;
}
export class DenoRuntime extends Runtime {

@@ -13,6 +30,7 @@ constructor() {

func(inp, out, { code, secrets = [], effect = fx.read() }) {
const matId = runtimes.registerDenoFunc({ code, secrets }, effect);
const source = stringifyFn(code);
const matId = runtimes.registerDenoFunc({ code: source, secrets }, effect);
const mat = {
_id: matId,
code,
code: source,
secrets,

@@ -43,3 +61,4 @@ effect,

};
return t.func(inp, inp, mat);
const out = wit_utils.removeInjections(inp._id);
return t.func(inp, new t.Typedef(out, {}), mat);
}

@@ -58,3 +77,3 @@ static(out, value) {

: { secrets: [], ...data };
return Policy.create(name, runtimes.registerDenoFunc(params, fx.read()));
return Policy.create(name, runtimes.registerDenoFunc({ ...params, code: stringifyFn(params.code) }, fx.read()));
}

@@ -61,0 +80,0 @@ importPolicy(data, name) {

@@ -7,4 +7,4 @@ import { Effect } from "../gen/interfaces/metatype-typegraph-runtimes.js";

constructor(endpoint: string);
query<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, path?: string[]): t.Func<P, I, O, QueryMat>;
mutation<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, effect: Effect, path?: string[]): t.Func<P, I, O, MutationMat>;
query<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, path?: string[]): t.Func<I, O, QueryMat>;
mutation<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, effect: Effect, path?: string[]): t.Func<I, O, MutationMat>;
}

@@ -11,0 +11,0 @@ interface QueryMat extends Materializer {

@@ -10,7 +10,7 @@ import * as t from "../types.js";

constructor(endpoint: string, certSecret?: string | undefined, basicAuthSecret?: string | undefined);
get<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">): t.Func<P, I, O>;
post<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<P, I, O>;
put<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<P, I, O>;
patch<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<P, I, O>;
delete_<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<P, I, O>;
get<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">): t.Func<I, O>;
post<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<I, O>;
put<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<I, O>;
patch<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<I, O>;
delete_<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, options: Omit<MaterializerHttpRequest, "method">, effect?: Effect): t.Func<I, O>;
}

@@ -29,6 +29,6 @@ // Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.

post(inp, out, options, effect) {
return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "get", inp, out, options, effect !== null && effect !== void 0 ? effect : fx.create());
return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "post", inp, out, options, effect !== null && effect !== void 0 ? effect : fx.create());
}
put(inp, out, options, effect) {
return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "get", inp, out, options, effect !== null && effect !== void 0 ? effect : fx.update());
return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "put", inp, out, options, effect !== null && effect !== void 0 ? effect : fx.update());
}

@@ -39,3 +39,3 @@ patch(inp, out, options, effect) {

delete_(inp, out, options, effect) {
return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "get", inp, out, options, effect !== null && effect !== void 0 ? effect : fx.delete_());
return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "delete", inp, out, options, effect !== null && effect !== void 0 ? effect : fx.delete_());
}

@@ -42,0 +42,0 @@ }

@@ -27,12 +27,8 @@ import * as t from "../types.js";

code: string;
}): t.Func<{
[key: string]: t.Typedef;
}, I, O, LambdaMat>;
}): t.Func<I, O, LambdaMat>;
fromDef<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, { code }: {
code: string;
}): t.Func<{
[key: string]: t.Typedef;
}, I, O, DefMat>;
import<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, { name, module, effect, secrets }: PythonImport): t.Func<P, I, O, ImportMat>;
}): t.Func<I, O, DefMat>;
import<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, { name, module, effect, secrets }: PythonImport): t.Func<I, O, ImportMat>;
}
export {};

@@ -9,6 +9,4 @@ import * as t from "../types.js";

constructor(data: RandomRuntimeData);
gen(out: t.Typedef): t.Func<{
[key: string]: t.Typedef;
}, t.Struct<{}>, t.Typedef, RandomMat>;
gen(out: t.Typedef): t.Func<t.Struct<{}>, t.Typedef, RandomMat>;
}
export {};

@@ -11,8 +11,8 @@ import * as t from "../types.js";

constructor();
wasi<P extends Record<string, t.Typedef> = Record<string, t.Typedef>, I extends t.Struct<P> = t.Struct<P>, O extends t.Typedef = t.Typedef>(inp: I, out: O, { func, wasm, effect }: {
wasi<I extends t.Typedef = t.Typedef, O extends t.Typedef = t.Typedef>(inp: I, out: O, { func, wasm, effect }: {
func: string;
wasm: string;
effect?: Effect;
}): t.Func<P, I, O, WasiMat>;
}): t.Func<I, O, WasiMat>;
}
export {};

@@ -0,5 +1,8 @@

import { ArtifactResolutionConfig } from "./gen/interfaces/metatype-typegraph-core.js";
import { TypegraphOutput } from "./typegraph.js";
export interface BasicAuth {
export declare class BasicAuth {
username: string;
password: string;
constructor(username: string, password: string);
asHeaderValue(): string;
}

@@ -9,5 +12,18 @@ export interface TypegraphDeployParams {

auth?: BasicAuth;
artifactsConfig?: ArtifactResolutionConfig;
secrets: Record<string, string>;
cliVersion: string;
}
export declare function tgDeploy(typegraph: TypegraphOutput, params: TypegraphDeployParams): Promise<string | Record<string, any>>;
export interface TypegraphRemoveParams {
baseUrl: string;
auth?: BasicAuth;
}
export interface DeployResult {
serialized: string;
typegate: Record<string, any> | string;
}
export interface RemoveResult {
typegate: Record<string, any> | string;
}
export declare function tgDeploy(typegraph: TypegraphOutput, params: TypegraphDeployParams): Promise<DeployResult>;
export declare function tgRemove(typegraph: TypegraphOutput, params: TypegraphRemoveParams): Promise<RemoveResult>;
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import { wit_utils } from "./wit.js";
export class BasicAuth {
constructor(username, password) {
this.username = username;
this.password = password;
}
asHeaderValue() {
return `Basic ${btoa(this.username + ":" + this.password)}`;
}
}
export async function tgDeploy(typegraph, params) {
const { baseUrl, cliVersion, secrets, auth } = params;
const { serialized } = typegraph;
const { baseUrl, cliVersion, secrets, auth, artifactsConfig } = params;
const serialized = typegraph.serialize(artifactsConfig);
const headers = new Headers();
headers.append("Content-Type", "application/json");
if (auth) {
headers.append("Authorization", `Basic ${btoa(auth.username + ":" + auth.password)}`);
headers.append("Authorization", auth.asHeaderValue());
}

@@ -15,3 +24,3 @@ const response = await fetch(new URL("/typegate", baseUrl), {

headers,
body: wit_utils.genGqlquery({
body: wit_utils.gqlDeployQuery({
cliVersion,

@@ -22,4 +31,23 @@ tg: serialized,

});
return handleResponse(response);
return {
serialized,
typegate: await handleResponse(response),
};
}
export async function tgRemove(typegraph, params) {
const { baseUrl, auth } = params;
const headers = new Headers();
headers.append("Content-Type", "application/json");
if (auth) {
headers.append("Authorization", auth.asHeaderValue());
}
const response = await fetch(new URL("/typegate", baseUrl), {
method: "POST",
headers,
body: wit_utils.gqlRemoveQuery([typegraph.name]),
});
return {
typegate: await handleResponse(response),
};
}
async function handleResponse(response) {

@@ -26,0 +54,0 @@ if (response.headers.get("Content-Type") == "application/json") {

import * as t from "./types.js";
import { InjectionValue } from "./utils/type_utils.js";
import { Auth, Cors as CorsWit, Rate } from "./wit.js";
import Policy from "./policy.js";
import { ArtifactResolutionConfig } from "./gen/interfaces/metatype-typegraph-core.js";
type Exports = Record<string, t.Func>;

@@ -17,4 +17,32 @@ type Cors = Partial<CorsWit>;

}
export interface TypegraphBuilderArgs {
expose: (exports: Exports, defaultPolicy?: Policy) => void;
export declare class ApplyFromArg {
name: string | null;
constructor(name: string | null);
}
export declare class ApplyFromStatic {
value: any;
constructor(value: any);
}
export declare class ApplyFromSecret {
key: string;
constructor(key: string);
}
export declare class ApplyFromContext {
key: string;
constructor(key: string);
}
export declare class ApplyFromParent {
typeName: string;
constructor(typeName: string);
}
declare const InjectionSource: {
readonly asArg: (name?: string) => ApplyFromArg;
readonly set: (value: any) => ApplyFromStatic;
readonly fromSecret: (key: string) => ApplyFromSecret;
readonly fromContext: (key: string) => ApplyFromContext;
readonly fromParent: (typeName: string) => ApplyFromParent;
};
type InjectionSourceType = typeof InjectionSource;
export interface TypegraphBuilderArgs extends InjectionSourceType {
expose: (exports: Exports, defaultPolicy?: t.PolicySpec | Array<t.PolicySpec>) => void;
inherit: () => InheritDef;

@@ -24,2 +52,5 @@ rest: (graphql: string) => number;

ref: (name: string) => t.Typedef;
configureRandomInjection: (params: {
seed: number;
}) => void;
}

@@ -33,2 +64,3 @@ export declare class InheritDef {

fromParent(value: InjectionValue<string>): this;
fromRandom(): this;
}

@@ -41,9 +73,9 @@ export type TypegraphBuilder = (g: TypegraphBuilderArgs) => void;

export interface TypegraphOutput {
serialized: string;
args: Omit<TypegraphArgs, "builder">;
serialize: (config?: ArtifactResolutionConfig) => string;
name: string;
}
export declare function typegraph(name: string, builder: TypegraphBuilder): void;
export declare function typegraph(args: TypegraphArgs): void;
export declare function typegraph(args: Omit<TypegraphArgs, "builder">, builder: TypegraphBuilder): void;
export declare function typegraph(name: string, builder: TypegraphBuilder): TypegraphOutput;
export declare function typegraph(args: TypegraphArgs): TypegraphOutput;
export declare function typegraph(args: Omit<TypegraphArgs, "builder">, builder: TypegraphBuilder): TypegraphOutput;
export declare function genRef(name: string): t.Typedef;
export {};

@@ -9,2 +9,34 @@ // Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.

import { getPolicyChain } from "./types.js";
export class ApplyFromArg {
constructor(name) {
this.name = name;
}
}
export class ApplyFromStatic {
constructor(value) {
this.value = value;
}
}
export class ApplyFromSecret {
constructor(key) {
this.key = key;
}
}
export class ApplyFromContext {
constructor(key) {
this.key = key;
}
}
export class ApplyFromParent {
constructor(typeName) {
this.typeName = typeName;
}
}
const InjectionSource = {
asArg: (name) => new ApplyFromArg(name !== null && name !== void 0 ? name : null),
set: (value) => new ApplyFromStatic(value),
fromSecret: (key) => new ApplyFromSecret(key),
fromContext: (key) => new ApplyFromContext(key),
fromParent: (typeName) => new ApplyFromParent(typeName),
};
export class InheritDef {

@@ -31,2 +63,6 @@ set(value) {

}
fromRandom() {
this.payload = serializeGenericInjection("random", null);
return this;
}
}

@@ -90,17 +126,27 @@ export class RawAuth {

},
configureRandomInjection: (params) => {
return core.setSeed(params.seed);
},
...InjectionSource,
};
builder(g);
const tgJson = core.finalizeTypegraph(disableAutoSerialization ? "resolve-artifacts" : "simple");
let serialize = () => "";
if (!disableAutoSerialization) {
const tgJson = core.finalizeTypegraph({ tag: "simple" });
console.log(tgJson);
serialize = () => tgJson;
}
else {
// config is known at deploy time
serialize = (config) => {
const tgJson = core.finalizeTypegraph({
tag: "resolve-artifacts",
val: config,
});
return tgJson;
};
}
return {
serialized: tgJson,
args: {
name,
cors,
dynamic,
rate,
secrets,
},
serialize,
name,
};

@@ -107,0 +153,0 @@ }

@@ -1,2 +0,2 @@

import { PolicySpec as WitPolicySpec, TypeBase, TypeEither, TypeFile, TypeFloat, TypeInteger, TypeList, TypeOptional, TypeString, TypeUnion } from "./gen/interfaces/metatype-typegraph-core.js";
import { ParameterTransform, PolicySpec as WitPolicySpec, TypeBase, TypeEither, TypeFile, TypeFloat, TypeInteger, TypeList, TypeOptional, TypeString, TypeUnion } from "./gen/interfaces/metatype-typegraph-core.js";
import { FuncParams } from "./gen/interfaces/metatype-typegraph-runtimes.js";

@@ -6,3 +6,3 @@ import { Materializer } from "./runtimes/mod.js";

import { InjectionValue } from "./utils/type_utils.js";
import { InheritDef } from "./typegraph.js";
import { ApplyFromArg, ApplyFromContext, ApplyFromParent, ApplyFromSecret, ApplyFromStatic, InheritDef } from "./typegraph.js";
export type PolicySpec = Policy | PolicyPerEffectObject | {

@@ -42,2 +42,3 @@ none: Policy;

fromParent(value: InjectionValue<string>): this;
fromRandom(): this;
}

@@ -83,2 +84,5 @@ declare class Boolean extends Typedef {

export declare function datetime(): StringT;
export declare function json(): StringT;
export declare function hostname(): StringT;
export declare function phone(): StringT;
export declare function enum_(variants: string[], base?: SimplifiedBase<TypeBase>): StringT;

@@ -127,20 +131,24 @@ declare class File extends Typedef {

}>(props: P, base?: SimplifiedBase<TypeBase>): Struct<P>;
export declare class Func<P extends {
[key: string]: Typedef;
} = Record<string, Typedef>, I extends Struct<P> = Struct<P>, O extends Typedef = Typedef, M extends Materializer = Materializer> extends Typedef {
type ApplyParamObjectNode = {
[key: string]: ApplyParamNode;
};
type ApplyParamArrayNode = Array<ApplyParamNode>;
type ApplyParamLeafNode = ApplyFromArg | ApplyFromStatic | ApplyFromContext | ApplyFromSecret | ApplyFromParent;
type ApplyParamNode = ApplyParamObjectNode | ApplyParamArrayNode | ApplyParamLeafNode;
export declare class Func<I extends Typedef = Typedef, O extends Typedef = Typedef, M extends Materializer = Materializer> extends Typedef {
inp: I;
out: O;
mat: M;
constructor(_id: number, inp: I, out: O, mat: M);
reduce(value: Record<string, unknown | InheritDef>): Func<{
[key: string]: Typedef;
}, Struct<P>, O, M>;
parameterTransform: ParameterTransform | null;
config: FuncConfig | null;
constructor(_id: number, inp: I, out: O, mat: M, parameterTransform?: ParameterTransform | null, config?: FuncConfig | null);
extend(fields: Record<string, Typedef>): Func<I, Typedef, M>;
reduce(value: Record<string, unknown | InheritDef>): Func<Typedef, O, M>;
apply(value: ApplyParamObjectNode): Func<Typedef, O, M>;
rate(inp: {
calls: boolean;
weight?: number;
}): Func<P, I, O, M>;
static fromTypeFunc(data: FuncParams): Func<{
}): Func<I, O, M>;
static fromTypeFunc(data: FuncParams): Func<Struct<{
[key: string]: Typedef;
}, Struct<{
[key: string]: Typedef;
}>, Typedef, {

@@ -154,5 +162,3 @@ _id: number;

};
export declare function func<P extends {
[key: string]: Typedef;
}, I extends Struct<P> = Struct<P>, O extends Typedef = Typedef, M extends Materializer = Materializer>(inp: I, out: O, mat: M, { rateCalls, rateWeight }?: FuncConfig): Func<P, I, O, M>;
export declare function func<I extends Typedef = Typedef, O extends Typedef = Typedef, M extends Materializer = Materializer>(inp: I, out: O, mat: M, transformData?: ParameterTransform | null, config?: FuncConfig | null): Func<I, O, M>;
export {};

@@ -8,2 +8,3 @@ // Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.

import { serializeFromParentInjection, serializeGenericInjection, serializeStaticInjection, } from "./utils/injection_utils.js";
import { ApplyFromArg, ApplyFromContext, ApplyFromParent, ApplyFromSecret, ApplyFromStatic, } from "./typegraph.js";
export function getPolicyChain(policy) {

@@ -103,2 +104,5 @@ const chain = Array.isArray(policy) ? policy : [policy];

}
fromRandom() {
return this.withInjection(serializeGenericInjection("random", null));
}
}

@@ -206,2 +210,11 @@ class Boolean extends Typedef {

}
export function json() {
return string({ format: "json" });
}
export function hostname() {
return string({ format: "hostname" });
}
export function phone() {
return string({ format: "phone" });
}
// Note: enum is a reserved word

@@ -323,4 +336,34 @@ export function enum_(variants, base = {}) {

}
function serializeApplyParamNode(node) {
if (node instanceof ApplyFromArg) {
return { source: "arg", name: node.name };
}
else if (node instanceof ApplyFromStatic) {
return { source: "static", value: JSON.stringify(node.value) };
}
else if (node instanceof ApplyFromContext) {
return { source: "context", key: node.key };
}
else if (node instanceof ApplyFromSecret) {
return { source: "secret", key: node.key };
}
else if (node instanceof ApplyFromParent) {
return { source: "parent", typeName: node.typeName };
}
else if (Array.isArray(node)) {
return {
type: "array",
items: node.map(serializeApplyParamNode),
};
}
else if (typeof node === "object" && node !== null) {
return {
type: "object",
fields: mapValues(node, serializeApplyParamNode),
};
}
throw new Error(`Unexpected node type: ${node}`);
}
export class Func extends Typedef {
constructor(_id, inp, out, mat) {
constructor(_id, inp, out, mat, parameterTransform = null, config = null) {
super(_id, {});

@@ -330,3 +373,9 @@ this.inp = inp;

this.mat = mat;
this.parameterTransform = parameterTransform;
this.config = config;
}
extend(fields) {
const output = core.extendStruct(this.out._id, Object.entries(fields).map(([name, typ]) => [name, typ._id]));
return func(this.inp, new Typedef(output, {}), this.mat, this.parameterTransform, this.config);
}
reduce(value) {

@@ -339,5 +388,15 @@ const data = {

}
apply(value) {
const serialized = serializeApplyParamNode(value);
if (typeof serialized !== "object" || serialized == null ||
serialized.type !== "object") {
throw new Error("Invalid apply value: root must be an object");
}
const transformTree = JSON.stringify(serialized.fields);
const transformData = core.getTransformData(this.inp._id, transformTree);
return func(new Typedef(transformData.queryInput, {}), this.out, this.mat, transformData.parameterTransform, this.config);
}
rate(inp) {
var _a;
return func(this.inp, this.out, this.mat, { rateCalls: (_a = inp.calls) !== null && _a !== void 0 ? _a : false, rateWeight: inp.weight });
return func(this.inp, this.out, this.mat, this.parameterTransform, { rateCalls: (_a = inp.calls) !== null && _a !== void 0 ? _a : false, rateWeight: inp.weight });
}

@@ -348,3 +407,6 @@ static fromTypeFunc(data) {

}
export function func(inp, out, mat, { rateCalls = false, rateWeight = undefined } = {}) {
export function func(inp, out, mat, transformData = null, config = null) {
var _a, _b;
const rateCalls = (_a = config === null || config === void 0 ? void 0 : config.rateCalls) !== null && _a !== void 0 ? _a : false;
const rateWeight = (_b = config === null || config === void 0 ? void 0 : config.rateWeight) !== null && _b !== void 0 ? _b : undefined;
return new Func(core.funcb({

@@ -354,5 +416,6 @@ inp: inp._id,

mat: mat._id,
parameterTransform: transformData !== null && transformData !== void 0 ? transformData : undefined,
rateCalls,
rateWeight,
}), inp, out, mat);
}), inp, out, mat, transformData, config);
}

@@ -31,2 +31,5 @@ // Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.

}
if (value === null) {
return JSON.stringify({ source, data: {} });
}
return JSON.stringify({

@@ -38,3 +41,3 @@ source,

export function serializeGenericInjection(source, value) {
const allowed = ["dynamic", "context", "secret"];
const allowed = ["dynamic", "context", "secret", "random"];
if (allowed.includes(source)) {

@@ -41,0 +44,0 @@ return serializeInjection(source, value);

@@ -18,4 +18,4 @@ import { PerEffect } from "../effects.js";

export type NullableOptional<T> = PickRequired<T> & Nullable<PickOptional<T>>;
export type InjectionSource = "dynamic" | "static" | "context" | "parent" | "secret";
export type InjectionSource = "dynamic" | "static" | "context" | "parent" | "secret" | "random";
export type InjectionValue<T> = T | PerEffect;
export {};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc