@flarequery/firebase 0.1.0 → 0.1.2

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/dist/index.d.cts CHANGED
@@ -1,37 +1,70 @@
1
+ import { QueryContext, FlareResponse, FlareCollectionResponse, ModelDefinition } from '@flarequery/core';
2
+ export { AuthRule, FieldDefinition, FlareResponse, ModelDefinition, QueryContext, RelationDefinition } from '@flarequery/core';
1
3
  import { Auth } from 'firebase-admin/auth';
2
4
  import { Firestore } from 'firebase-admin/firestore';
3
5
  import * as firebase_functions_v2_https from 'firebase-functions/v2/https';
4
6
  import * as functionsV1 from 'firebase-functions/v1';
5
7
 
6
- type RelationType = "one" | "many";
7
- interface RelationDefinition {
8
- from: string;
9
- to: string;
10
- type: RelationType;
11
- }
12
- type ScalarType = "string" | "number" | "boolean" | "timestamp";
13
- interface RelationFieldDefinition {
14
- relation: RelationDefinition;
15
- select?: string[];
16
- }
17
- type FieldDefinition = ScalarType | RelationFieldDefinition;
18
- interface ModelDefinition {
19
- source: FirestoreCollectionRef;
20
- fields: Record<string, FieldDefinition>;
21
- auth?: AuthRule;
22
- }
23
- type AuthRule = (ctx: QueryContext) => boolean;
24
- interface QueryContext {
25
- userId: string | null;
26
- token: Record<string, unknown> | null;
27
- }
28
- interface FirestoreCollectionRef {
29
- readonly path: string;
30
- }
31
- type FlareResult = Record<string, unknown>;
32
- interface FlareResponse {
33
- data: FlareResult | null;
34
- errors?: string[];
8
+ interface CollectionReference {
9
+ /**
10
+ * Fetch a single document by ID.
11
+ * @example app.collection("Product").doc("abc123")
12
+ */
13
+ doc(id: string): DocumentReference;
14
+ /**
15
+ * Start a collection query with a filter.
16
+ * @example app.collection("Product").filter("oem").equals("Canon")
17
+ */
18
+ filter(field: string): FilterBuilder;
19
+ }
20
+ interface DocumentReference {
21
+ /**
22
+ * Select specific fields to fetch. Use dot notation for relations.
23
+ * @example .select("name", "price", "participants.name")
24
+ */
25
+ select(...fields: string[]): Query;
26
+ }
27
+ interface Query {
28
+ get(ctx: QueryContext): Promise<FlareResponse>;
29
+ }
30
+ /**
31
+ * FilterBuilder — returned by .filter("fieldName")
32
+ * @example
33
+ * .filter("oem").equals("Canon")
34
+ * .filter("price").gte(100)
35
+ * .filter("price").gte(100).lte(500)
36
+ * .filter("status").in(["New", "Clearout"])
37
+ * .filter("tags").contains("laser")
38
+ * .filter("status").not("Discontinued")
39
+ */
40
+ interface FilterBuilder {
41
+ equals(value: string | number | boolean): CollectionQuery;
42
+ not(value: string | number | boolean): CollectionQuery;
43
+ gt(value: number | string): CollectionQuery;
44
+ gte(value: number | string): CollectionQuery;
45
+ lt(value: number | string): CollectionQuery;
46
+ lte(value: number | string): CollectionQuery;
47
+ in(values: (string | number)[]): CollectionQuery;
48
+ contains(value: string | number): CollectionQuery;
49
+ }
50
+ /**
51
+ * CollectionQuery — the chainable query builder.
52
+ * @example
53
+ * app.collection("Product")
54
+ * .filter("oem").equals("Canon")
55
+ * .filter("isActive").equals(true)
56
+ * .filter("price").gte(50)
57
+ * .select("name", "price", "rtsPN")
58
+ * .orderBy("name", "asc")
59
+ * .limit(50)
60
+ * .get(ctx)
61
+ */
62
+ interface CollectionQuery {
63
+ filter(field: string): FilterBuilder;
64
+ select(...fields: string[]): CollectionQuery;
65
+ orderBy(field: string, direction: "asc" | "desc"): CollectionQuery;
66
+ limit(n: number): CollectionQuery;
67
+ get(ctx: QueryContext): Promise<FlareCollectionResponse>;
35
68
  }
36
69
 
37
70
  interface ServerlessAppOptions {
@@ -40,9 +73,10 @@ interface ServerlessAppOptions {
40
73
  }
41
74
  interface ServerlessApp {
42
75
  model(name: string, definition: ModelDefinition): void;
43
- execute(query: string, ctx: QueryContext): Promise<FlareResponse>;
76
+ collection(name: string): CollectionReference;
44
77
  }
45
78
  declare function createServerlessApp(options: ServerlessAppOptions): ServerlessApp;
79
+ declare function extractContext(authorization: string | undefined, auth: Auth): Promise<QueryContext>;
46
80
 
47
81
  interface FunctionOptions {
48
82
  cors?: boolean;
@@ -50,4 +84,4 @@ interface FunctionOptions {
50
84
  declare function createFunction(app: ServerlessApp, auth: Auth, options?: FunctionOptions): functionsV1.HttpsFunction;
51
85
  declare function createOnRequest(app: ServerlessApp, auth: Auth, options?: FunctionOptions): firebase_functions_v2_https.HttpsFunction;
52
86
 
53
- export { type AuthRule, type FieldDefinition, type FlareResponse, type ModelDefinition, type QueryContext, type RelationDefinition, createFunction, createOnRequest, createServerlessApp };
87
+ export { type CollectionReference, type DocumentReference, type FunctionOptions, type Query, type ServerlessApp, type ServerlessAppOptions, createFunction, createOnRequest, createServerlessApp, extractContext };
package/dist/index.d.ts CHANGED
@@ -1,37 +1,70 @@
1
+ import { QueryContext, FlareResponse, FlareCollectionResponse, ModelDefinition } from '@flarequery/core';
2
+ export { AuthRule, FieldDefinition, FlareResponse, ModelDefinition, QueryContext, RelationDefinition } from '@flarequery/core';
1
3
  import { Auth } from 'firebase-admin/auth';
2
4
  import { Firestore } from 'firebase-admin/firestore';
3
5
  import * as firebase_functions_v2_https from 'firebase-functions/v2/https';
4
6
  import * as functionsV1 from 'firebase-functions/v1';
5
7
 
6
- type RelationType = "one" | "many";
7
- interface RelationDefinition {
8
- from: string;
9
- to: string;
10
- type: RelationType;
11
- }
12
- type ScalarType = "string" | "number" | "boolean" | "timestamp";
13
- interface RelationFieldDefinition {
14
- relation: RelationDefinition;
15
- select?: string[];
16
- }
17
- type FieldDefinition = ScalarType | RelationFieldDefinition;
18
- interface ModelDefinition {
19
- source: FirestoreCollectionRef;
20
- fields: Record<string, FieldDefinition>;
21
- auth?: AuthRule;
22
- }
23
- type AuthRule = (ctx: QueryContext) => boolean;
24
- interface QueryContext {
25
- userId: string | null;
26
- token: Record<string, unknown> | null;
27
- }
28
- interface FirestoreCollectionRef {
29
- readonly path: string;
30
- }
31
- type FlareResult = Record<string, unknown>;
32
- interface FlareResponse {
33
- data: FlareResult | null;
34
- errors?: string[];
8
+ interface CollectionReference {
9
+ /**
10
+ * Fetch a single document by ID.
11
+ * @example app.collection("Product").doc("abc123")
12
+ */
13
+ doc(id: string): DocumentReference;
14
+ /**
15
+ * Start a collection query with a filter.
16
+ * @example app.collection("Product").filter("oem").equals("Canon")
17
+ */
18
+ filter(field: string): FilterBuilder;
19
+ }
20
+ interface DocumentReference {
21
+ /**
22
+ * Select specific fields to fetch. Use dot notation for relations.
23
+ * @example .select("name", "price", "participants.name")
24
+ */
25
+ select(...fields: string[]): Query;
26
+ }
27
+ interface Query {
28
+ get(ctx: QueryContext): Promise<FlareResponse>;
29
+ }
30
+ /**
31
+ * FilterBuilder — returned by .filter("fieldName")
32
+ * @example
33
+ * .filter("oem").equals("Canon")
34
+ * .filter("price").gte(100)
35
+ * .filter("price").gte(100).lte(500)
36
+ * .filter("status").in(["New", "Clearout"])
37
+ * .filter("tags").contains("laser")
38
+ * .filter("status").not("Discontinued")
39
+ */
40
+ interface FilterBuilder {
41
+ equals(value: string | number | boolean): CollectionQuery;
42
+ not(value: string | number | boolean): CollectionQuery;
43
+ gt(value: number | string): CollectionQuery;
44
+ gte(value: number | string): CollectionQuery;
45
+ lt(value: number | string): CollectionQuery;
46
+ lte(value: number | string): CollectionQuery;
47
+ in(values: (string | number)[]): CollectionQuery;
48
+ contains(value: string | number): CollectionQuery;
49
+ }
50
+ /**
51
+ * CollectionQuery — the chainable query builder.
52
+ * @example
53
+ * app.collection("Product")
54
+ * .filter("oem").equals("Canon")
55
+ * .filter("isActive").equals(true)
56
+ * .filter("price").gte(50)
57
+ * .select("name", "price", "rtsPN")
58
+ * .orderBy("name", "asc")
59
+ * .limit(50)
60
+ * .get(ctx)
61
+ */
62
+ interface CollectionQuery {
63
+ filter(field: string): FilterBuilder;
64
+ select(...fields: string[]): CollectionQuery;
65
+ orderBy(field: string, direction: "asc" | "desc"): CollectionQuery;
66
+ limit(n: number): CollectionQuery;
67
+ get(ctx: QueryContext): Promise<FlareCollectionResponse>;
35
68
  }
36
69
 
37
70
  interface ServerlessAppOptions {
@@ -40,9 +73,10 @@ interface ServerlessAppOptions {
40
73
  }
41
74
  interface ServerlessApp {
42
75
  model(name: string, definition: ModelDefinition): void;
43
- execute(query: string, ctx: QueryContext): Promise<FlareResponse>;
76
+ collection(name: string): CollectionReference;
44
77
  }
45
78
  declare function createServerlessApp(options: ServerlessAppOptions): ServerlessApp;
79
+ declare function extractContext(authorization: string | undefined, auth: Auth): Promise<QueryContext>;
46
80
 
47
81
  interface FunctionOptions {
48
82
  cors?: boolean;
@@ -50,4 +84,4 @@ interface FunctionOptions {
50
84
  declare function createFunction(app: ServerlessApp, auth: Auth, options?: FunctionOptions): functionsV1.HttpsFunction;
51
85
  declare function createOnRequest(app: ServerlessApp, auth: Auth, options?: FunctionOptions): firebase_functions_v2_https.HttpsFunction;
52
86
 
53
- export { type AuthRule, type FieldDefinition, type FlareResponse, type ModelDefinition, type QueryContext, type RelationDefinition, createFunction, createOnRequest, createServerlessApp };
87
+ export { type CollectionReference, type DocumentReference, type FunctionOptions, type Query, type ServerlessApp, type ServerlessAppOptions, createFunction, createOnRequest, createServerlessApp, extractContext };