phibelle-kit 1.0.4 → 1.0.7

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.
@@ -1,23 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated `api` utility.
4
- *
5
- * THIS CODE IS AUTOMATICALLY GENERATED.
6
- *
7
- * To regenerate, run `npx convex dev`.
8
- * @module
9
- */
10
-
11
- import { anyApi, componentsGeneric } from "convex/server";
12
-
13
- /**
14
- * A utility for referencing Convex functions in your app's API.
15
- *
16
- * Usage:
17
- * ```js
18
- * const myFunctionReference = api.myModule.myFunction;
19
- * ```
20
- */
21
- export const api = anyApi;
22
- export const internal = anyApi;
23
- export const components = componentsGeneric();
@@ -1,60 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated data model types.
4
- *
5
- * THIS CODE IS AUTOMATICALLY GENERATED.
6
- *
7
- * To regenerate, run `npx convex dev`.
8
- * @module
9
- */
10
-
11
- import type {
12
- DataModelFromSchemaDefinition,
13
- DocumentByName,
14
- TableNamesInDataModel,
15
- SystemTableNames,
16
- } from "convex/server";
17
- import type { GenericId } from "convex/values";
18
- import schema from "../schema.js";
19
-
20
- /**
21
- * The names of all of your Convex tables.
22
- */
23
- export type TableNames = TableNamesInDataModel<DataModel>;
24
-
25
- /**
26
- * The type of a document stored in Convex.
27
- *
28
- * @typeParam TableName - A string literal type of the table name (like "users").
29
- */
30
- export type Doc<TableName extends TableNames> = DocumentByName<
31
- DataModel,
32
- TableName
33
- >;
34
-
35
- /**
36
- * An identifier for a document in Convex.
37
- *
38
- * Convex documents are uniquely identified by their `Id`, which is accessible
39
- * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
40
- *
41
- * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
42
- *
43
- * IDs are just strings at runtime, but this type can be used to distinguish them from other
44
- * strings when type checking.
45
- *
46
- * @typeParam TableName - A string literal type of the table name (like "users").
47
- */
48
- export type Id<TableName extends TableNames | SystemTableNames> =
49
- GenericId<TableName>;
50
-
51
- /**
52
- * A type describing your Convex data model.
53
- *
54
- * This type includes information about what tables you have, the type of
55
- * documents stored in those tables, and the indexes defined on them.
56
- *
57
- * This type is used to parameterize methods like `queryGeneric` and
58
- * `mutationGeneric` to make them type-safe.
59
- */
60
- export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -1,143 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated utilities for implementing server-side Convex query and mutation functions.
4
- *
5
- * THIS CODE IS AUTOMATICALLY GENERATED.
6
- *
7
- * To regenerate, run `npx convex dev`.
8
- * @module
9
- */
10
-
11
- import {
12
- ActionBuilder,
13
- HttpActionBuilder,
14
- MutationBuilder,
15
- QueryBuilder,
16
- GenericActionCtx,
17
- GenericMutationCtx,
18
- GenericQueryCtx,
19
- GenericDatabaseReader,
20
- GenericDatabaseWriter,
21
- } from "convex/server";
22
- import type { DataModel } from "./dataModel.js";
23
-
24
- /**
25
- * Define a query in this Convex app's public API.
26
- *
27
- * This function will be allowed to read your Convex database and will be accessible from the client.
28
- *
29
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
30
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
31
- */
32
- export declare const query: QueryBuilder<DataModel, "public">;
33
-
34
- /**
35
- * Define a query that is only accessible from other Convex functions (but not from the client).
36
- *
37
- * This function will be allowed to read from your Convex database. It will not be accessible from the client.
38
- *
39
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
40
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
41
- */
42
- export declare const internalQuery: QueryBuilder<DataModel, "internal">;
43
-
44
- /**
45
- * Define a mutation in this Convex app's public API.
46
- *
47
- * This function will be allowed to modify your Convex database and will be accessible from the client.
48
- *
49
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
50
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
51
- */
52
- export declare const mutation: MutationBuilder<DataModel, "public">;
53
-
54
- /**
55
- * Define a mutation that is only accessible from other Convex functions (but not from the client).
56
- *
57
- * This function will be allowed to modify your Convex database. It will not be accessible from the client.
58
- *
59
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
60
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
61
- */
62
- export declare const internalMutation: MutationBuilder<DataModel, "internal">;
63
-
64
- /**
65
- * Define an action in this Convex app's public API.
66
- *
67
- * An action is a function which can execute any JavaScript code, including non-deterministic
68
- * code and code with side-effects, like calling third-party services.
69
- * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
70
- * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
71
- *
72
- * @param func - The action. It receives an {@link ActionCtx} as its first argument.
73
- * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
74
- */
75
- export declare const action: ActionBuilder<DataModel, "public">;
76
-
77
- /**
78
- * Define an action that is only accessible from other Convex functions (but not from the client).
79
- *
80
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
81
- * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
82
- */
83
- export declare const internalAction: ActionBuilder<DataModel, "internal">;
84
-
85
- /**
86
- * Define an HTTP action.
87
- *
88
- * The wrapped function will be used to respond to HTTP requests received
89
- * by a Convex deployment if the requests matches the path and method where
90
- * this action is routed. Be sure to route your httpAction in `convex/http.js`.
91
- *
92
- * @param func - The function. It receives an {@link ActionCtx} as its first argument
93
- * and a Fetch API `Request` object as its second.
94
- * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
95
- */
96
- export declare const httpAction: HttpActionBuilder;
97
-
98
- /**
99
- * A set of services for use within Convex query functions.
100
- *
101
- * The query context is passed as the first argument to any Convex query
102
- * function run on the server.
103
- *
104
- * This differs from the {@link MutationCtx} because all of the services are
105
- * read-only.
106
- */
107
- export type QueryCtx = GenericQueryCtx<DataModel>;
108
-
109
- /**
110
- * A set of services for use within Convex mutation functions.
111
- *
112
- * The mutation context is passed as the first argument to any Convex mutation
113
- * function run on the server.
114
- */
115
- export type MutationCtx = GenericMutationCtx<DataModel>;
116
-
117
- /**
118
- * A set of services for use within Convex action functions.
119
- *
120
- * The action context is passed as the first argument to any Convex action
121
- * function run on the server.
122
- */
123
- export type ActionCtx = GenericActionCtx<DataModel>;
124
-
125
- /**
126
- * An interface to read from the database within Convex query functions.
127
- *
128
- * The two entry points are {@link DatabaseReader.get}, which fetches a single
129
- * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
130
- * building a query.
131
- */
132
- export type DatabaseReader = GenericDatabaseReader<DataModel>;
133
-
134
- /**
135
- * An interface to read from and write to the database within Convex mutation
136
- * functions.
137
- *
138
- * Convex guarantees that all writes within a single mutation are
139
- * executed atomically, so you never have to worry about partial writes leaving
140
- * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
141
- * for the guarantees Convex provides your functions.
142
- */
143
- export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -1,93 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Generated utilities for implementing server-side Convex query and mutation functions.
4
- *
5
- * THIS CODE IS AUTOMATICALLY GENERATED.
6
- *
7
- * To regenerate, run `npx convex dev`.
8
- * @module
9
- */
10
-
11
- import {
12
- actionGeneric,
13
- httpActionGeneric,
14
- queryGeneric,
15
- mutationGeneric,
16
- internalActionGeneric,
17
- internalMutationGeneric,
18
- internalQueryGeneric,
19
- } from "convex/server";
20
-
21
- /**
22
- * Define a query in this Convex app's public API.
23
- *
24
- * This function will be allowed to read your Convex database and will be accessible from the client.
25
- *
26
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
27
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
28
- */
29
- export const query = queryGeneric;
30
-
31
- /**
32
- * Define a query that is only accessible from other Convex functions (but not from the client).
33
- *
34
- * This function will be allowed to read from your Convex database. It will not be accessible from the client.
35
- *
36
- * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
37
- * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
38
- */
39
- export const internalQuery = internalQueryGeneric;
40
-
41
- /**
42
- * Define a mutation in this Convex app's public API.
43
- *
44
- * This function will be allowed to modify your Convex database and will be accessible from the client.
45
- *
46
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
47
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
48
- */
49
- export const mutation = mutationGeneric;
50
-
51
- /**
52
- * Define a mutation that is only accessible from other Convex functions (but not from the client).
53
- *
54
- * This function will be allowed to modify your Convex database. It will not be accessible from the client.
55
- *
56
- * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
57
- * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
58
- */
59
- export const internalMutation = internalMutationGeneric;
60
-
61
- /**
62
- * Define an action in this Convex app's public API.
63
- *
64
- * An action is a function which can execute any JavaScript code, including non-deterministic
65
- * code and code with side-effects, like calling third-party services.
66
- * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
67
- * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
68
- *
69
- * @param func - The action. It receives an {@link ActionCtx} as its first argument.
70
- * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
71
- */
72
- export const action = actionGeneric;
73
-
74
- /**
75
- * Define an action that is only accessible from other Convex functions (but not from the client).
76
- *
77
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
78
- * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
79
- */
80
- export const internalAction = internalActionGeneric;
81
-
82
- /**
83
- * Define an HTTP action.
84
- *
85
- * The wrapped function will be used to respond to HTTP requests received
86
- * by a Convex deployment if the requests matches the path and method where
87
- * this action is routed. Be sure to route your httpAction in `convex/http.js`.
88
- *
89
- * @param func - The function. It receives an {@link ActionCtx} as its first argument
90
- * and a Fetch API `Request` object as its second.
91
- * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
92
- */
93
- export const httpAction = httpActionGeneric;
package/src/index.ts DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from "chalk";
4
- import { watchSceneCommand } from "./commands/watch-scene.js";
5
- import { cloneSceneCommand } from "./commands/clone-scene.js";
6
- import { waitForToken } from "./lib/wait-for-token.js";
7
-
8
- const USAGE = " Usage: phibelle-kit clone <sceneId> | phibelle-kit watch <sceneId>";
9
-
10
- async function main() {
11
- const command = process.argv[2];
12
- const sceneId = process.argv[3];
13
-
14
- if (!command || !sceneId) {
15
- console.log(chalk.red(" Command and scene ID are required"));
16
- console.log(chalk.gray(USAGE));
17
- process.exit(1);
18
- }
19
-
20
- await waitForToken();
21
-
22
- if (command === "clone") {
23
- await cloneSceneCommand(sceneId);
24
- process.exit(0);
25
- } else if (command === "watch") {
26
- await watchSceneCommand(sceneId);
27
- } else {
28
- console.log(chalk.red(` Unknown command: ${command}`));
29
- console.log(chalk.gray(USAGE));
30
- process.exit(1);
31
- }
32
- }
33
-
34
- main().catch((error) => {
35
- console.error(chalk.red("Error:"), error.message);
36
- process.exit(1);
37
- });
package/src/lib/conf.ts DELETED
@@ -1,28 +0,0 @@
1
- import crypto from "crypto";
2
- import Conf from "conf";
3
-
4
- const CONFIG = new Conf({
5
- projectName: "phibelle-kit",
6
- });
7
-
8
- export function setToken(token: string) {
9
- CONFIG.set("authToken", token);
10
- }
11
-
12
- export function getStoredToken(): string | undefined {
13
- return CONFIG.get("authToken") as string | undefined;
14
- }
15
-
16
- export function clearToken() {
17
- CONFIG.delete("authToken");
18
- }
19
-
20
- /** Stable session ID for this CLI instance; used so we can skip re-unpack when we were the ones who saved. */
21
- export function getSessionId(): string {
22
- let sessionId = CONFIG.get("sessionId") as string | undefined;
23
- if (!sessionId) {
24
- sessionId = crypto.randomUUID();
25
- CONFIG.set("sessionId", sessionId);
26
- }
27
- return sessionId;
28
- }
@@ -1,101 +0,0 @@
1
- import { ConvexClient } from "convex/browser";
2
- import { CONVEX_URL } from "./public-env.js";
3
- import { getStoredToken } from "./conf.js";
4
-
5
- if (!CONVEX_URL) {
6
- throw new Error(
7
- "Missing CONVEX_URL environment variable. " +
8
- "Set it to your Convex deployment URL (e.g., from NEXT_PUBLIC_CONVEX_URL in your phibelle project)"
9
- );
10
- }
11
-
12
- export function createConvexClient(): ConvexClient {
13
- const token = getStoredToken();
14
-
15
- if (!token) {
16
- throw new Error("Not authenticated. Please run 'phibelle login' first.");
17
- }
18
-
19
- const client = new ConvexClient(CONVEX_URL!);
20
-
21
- client.setAuth(() => Promise.resolve(token));
22
-
23
- return client;
24
- }
25
-
26
- /**
27
- * Helper function to subscribe to a Convex query.
28
- *
29
- * @param query - The query function reference (e.g., api.scenes.getById)
30
- * @param args - Arguments to pass to the query
31
- * @param callback - Callback function that receives the query result whenever it updates
32
- * @returns Unsubscribe function that can be called to stop the subscription
33
- *
34
- * @example
35
- * ```typescript
36
- * const unsubscribe = subscribeToQuery(
37
- * api.scenes.getById,
38
- * { id: "scene123" },
39
- * (scene) => {
40
- * console.log("Scene updated:", scene);
41
- * }
42
- * );
43
- *
44
- * // Later, to unsubscribe:
45
- * unsubscribe();
46
- * ```
47
- */
48
- export function subscribeToQuery<Args extends Record<string, any>, Result>(
49
- query: any, // Query reference from api
50
- args: Args,
51
- callback: (result: Result) => void
52
- ): () => void {
53
- const client = createConvexClient();
54
-
55
- return client.onUpdate(query, args, callback);
56
- }
57
-
58
- /**
59
- * Helper function to run a Convex query once and return the result.
60
- *
61
- * @param query - The query function reference (e.g., api.scenes.listMyScenes)
62
- * @param args - Arguments to pass to the query
63
- * @returns Promise that resolves with the query result
64
- *
65
- * @example
66
- * ```typescript
67
- * const scenes = await queryOnce(api.scenes.listMyScenes, {});
68
- * ```
69
- */
70
- export async function queryOnce<Args extends Record<string, any>, Result>(
71
- query: any,
72
- args: Args
73
- ): Promise<Result> {
74
- const client = createConvexClient();
75
-
76
- try {
77
- return await client.query(query, args);
78
- } finally {
79
- await client.close();
80
- }
81
- }
82
-
83
- /**
84
- * Helper function to run a Convex mutation once and return the result.
85
- *
86
- * @param mutation - The mutation function reference (e.g. api.scenes.update)
87
- * @param args - Arguments to pass to the mutation
88
- * @returns Promise that resolves with the mutation result
89
- */
90
- export async function mutateOnce<Args extends Record<string, any>, Result>(
91
- mutation: any,
92
- args: Args
93
- ): Promise<Result> {
94
- const client = createConvexClient();
95
-
96
- try {
97
- return await client.mutation(mutation, args);
98
- } finally {
99
- await client.close();
100
- }
101
- }
@@ -1,53 +0,0 @@
1
- import * as path from "node:path";
2
- import * as fs from "fs";
3
-
4
- export function folderExists(folderPath: string): boolean {
5
- return fs.existsSync(folderPath);
6
- }
7
-
8
- export function createFolder(folderPath: string) {
9
- if (!folderExists(folderPath)) {
10
- fs.mkdirSync(folderPath, { recursive: true });
11
- }
12
- }
13
-
14
- /** Scene name to folder name: lowercased, spaces to hyphens, safe for filesystem. */
15
- export function sceneNameToFolder(name: string): string {
16
- return name
17
- .toLowerCase()
18
- .replace(/\s+/g, "-")
19
- .replace(/[^a-z0-9-]/g, "")
20
- .replace(/-+/g, "-")
21
- .replace(/^-|-$/g, "") || "scene";
22
- }
23
-
24
- /** Find directory containing scene.json with _id === sceneId: check cwd first, then subdirs. */
25
- export function findSceneDirBySceneId(cwd: string, sceneId: string): string | null {
26
- const scenePathInCwd = path.join(cwd, "scene.json");
27
- try {
28
- const raw = fs.readFileSync(scenePathInCwd, "utf8");
29
- const data = JSON.parse(raw) as { _id?: string };
30
- if (data._id === sceneId) return cwd;
31
- } catch {
32
- // cwd is not the scene dir
33
- }
34
-
35
- let entries: fs.Dirent[];
36
- try {
37
- entries = fs.readdirSync(cwd, { withFileTypes: true });
38
- } catch {
39
- return null;
40
- }
41
- for (const ent of entries) {
42
- if (!ent.isDirectory()) continue;
43
- const scenePath = path.join(cwd, ent.name, "scene.json");
44
- try {
45
- const raw = fs.readFileSync(scenePath, "utf8");
46
- const data = JSON.parse(raw) as { _id?: string };
47
- if (data._id === sceneId) return path.join(cwd, ent.name);
48
- } catch {
49
- // no scene.json or invalid
50
- }
51
- }
52
- return null;
53
- }
@@ -1,73 +0,0 @@
1
- import chalk from "chalk";
2
- import * as path from "path";
3
- import * as fs from "fs";
4
- import { BASE_URL } from "./public-env.js";
5
- import { createFolder } from "./file-system.js";
6
- import { unpackageScene } from "./scene-packaging.js";
7
- import { createScriptWatcher, type ScriptWatcher } from "./script-watcher.js";
8
- import { setupSceneDirectory, getInstallHint } from "../package/setup.js";
9
- import { toErrorMessage } from "./utils.js";
10
- import type { Scene } from "./types.js";
11
-
12
- export type WatchCallbacks = {
13
- onPushed: (file: string) => void;
14
- onNewEntity: (engineId: number) => void;
15
- onError: (file: string, err: Error) => void;
16
- };
17
-
18
- const INSTALL_HINT_LABEL = " ⚠ Install dependencies for types and intellisense:";
19
-
20
- /** Create scene dir, write scene.json, setup package.json/global.d.ts; log install hint if needed. */
21
- export function setupSceneFiles(scene: Scene, sceneDir: string, ignoreHint: boolean = false): void {
22
- createFolder(sceneDir);
23
- fs.writeFileSync(path.join(sceneDir, "scene.json"), JSON.stringify(scene));
24
- const { shouldPromptInstall } = setupSceneDirectory(sceneDir, scene._id);
25
- if (shouldPromptInstall && !ignoreHint) {
26
- console.log(chalk.yellowBright.bold(INSTALL_HINT_LABEL));
27
- console.log(chalk.cyan.bold(" " + getInstallHint(sceneDir)));
28
- console.log();
29
- }
30
- }
31
-
32
- /** Unpackage scene scripts; log success or hint on failure. */
33
- export async function unpackageWithLogging(
34
- sceneId: string,
35
- sceneDir: string,
36
- failHint: string
37
- ): Promise<void> {
38
- try {
39
- await unpackageScene(sceneId, sceneDir);
40
- console.log(chalk.green(" ✓ Unpacked scene scripts (scene.tsx, entity-*.tsx, manifest.json)"));
41
- } catch (e: unknown) {
42
- console.log(chalk.yellow(" ⚠ Could not unpackage scene scripts: " + toErrorMessage(e)));
43
- console.log(chalk.gray(" " + failHint));
44
- }
45
- }
46
-
47
- export async function runFirstUpdateSetup(
48
- scene: Scene,
49
- sceneDir: string,
50
- callbacks: WatchCallbacks
51
- ): Promise<ScriptWatcher> {
52
- setupSceneFiles(scene, sceneDir);
53
-
54
- console.log(chalk.yellow(" Opening folder: " + sceneDir));
55
- console.log();
56
-
57
- await unpackageWithLogging(scene._id, sceneDir, "Edit in the app once to create a scene file, then run watch again.");
58
-
59
- console.log(chalk.green(" ✓ Connected to scene"));
60
- console.log(chalk.white(` Name: ${scene.name}`));
61
- console.log(chalk.white(` Dir: ${sceneDir}`));
62
- console.log(chalk.white(` Last updated: ${new Date(scene.updatedAt).toLocaleString()}`));
63
- console.log(chalk.white(" Scene Link: ") + chalk.cyan(`${BASE_URL}/editor?sceneId=${scene._id}`));
64
- console.log();
65
-
66
- return createScriptWatcher(
67
- scene._id,
68
- sceneDir,
69
- callbacks.onPushed,
70
- callbacks.onNewEntity,
71
- callbacks.onError
72
- );
73
- }
@@ -1,3 +0,0 @@
1
- export const isDev = process.env.NODE_ENV === "development";
2
- export const BASE_URL = isDev ? "http://localhost:3131" : "https://phibelle.studio";
3
- export const CONVEX_URL = isDev ? "https://mellow-toad-676.convex.cloud" : "https://keen-dove-500.convex.cloud";