@speakableio/core 0.1.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/dist/index.d.mts +90 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +86 -0
- package/dist/index.mjs +86 -0
- package/package.json +57 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
5
|
+
import * as firebase_firestore from 'firebase/firestore';
|
|
6
|
+
import { Firestore } from 'firebase/firestore';
|
|
7
|
+
import { FirebaseFirestoreTypes } from '@react-native-firebase/firestore';
|
|
8
|
+
|
|
9
|
+
interface AssignmentWithId extends Assignment {
|
|
10
|
+
ltiLineItemId: null;
|
|
11
|
+
id: string;
|
|
12
|
+
}
|
|
13
|
+
interface Assignment {
|
|
14
|
+
name: string;
|
|
15
|
+
scheduledTime: string | null;
|
|
16
|
+
dueTime?: {
|
|
17
|
+
hours: number;
|
|
18
|
+
minutes: number;
|
|
19
|
+
nanos: number;
|
|
20
|
+
};
|
|
21
|
+
speakableio: boolean;
|
|
22
|
+
owners: string[];
|
|
23
|
+
image: {
|
|
24
|
+
path: string | null;
|
|
25
|
+
url: string;
|
|
26
|
+
};
|
|
27
|
+
dueDate: {
|
|
28
|
+
day: number;
|
|
29
|
+
month: number;
|
|
30
|
+
year: number;
|
|
31
|
+
};
|
|
32
|
+
teacherName: string;
|
|
33
|
+
courseWorkId: string | null;
|
|
34
|
+
dueDateTimestamp: {
|
|
35
|
+
seconds: number;
|
|
36
|
+
nanoseconds: number;
|
|
37
|
+
};
|
|
38
|
+
scheduledTimeTimestamp: number;
|
|
39
|
+
active: boolean;
|
|
40
|
+
voice: string | null;
|
|
41
|
+
setId: string;
|
|
42
|
+
dateMade: {
|
|
43
|
+
seconds: number;
|
|
44
|
+
nanoseconds: number;
|
|
45
|
+
};
|
|
46
|
+
maxPoints: number;
|
|
47
|
+
courseId: string;
|
|
48
|
+
isAssessment: boolean;
|
|
49
|
+
isAvailable: boolean;
|
|
50
|
+
}
|
|
51
|
+
type AssignmentAnalyticsType = 'macro' | 'gradebook' | 'cards' | 'student' | 'student_summary';
|
|
52
|
+
|
|
53
|
+
type FirebaseInstance = FirebaseFirestoreTypes.Module | Firestore;
|
|
54
|
+
type FirestoreDB = Firestore;
|
|
55
|
+
type FirestoreHelpers = typeof firebase_firestore;
|
|
56
|
+
|
|
57
|
+
declare const createAssignmentRepo: (db: FirestoreDB, h: FirestoreHelpers) => {
|
|
58
|
+
get(id: string): Promise<AssignmentWithId | null>;
|
|
59
|
+
list(): Promise<AssignmentWithId[]>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
declare const assignmentQueryKeys: {
|
|
63
|
+
all: readonly ["assignments"];
|
|
64
|
+
byId: (id: string) => readonly ["assignments", string];
|
|
65
|
+
list: () => readonly ["assignments", "list"];
|
|
66
|
+
};
|
|
67
|
+
declare function useAssignment(id: string): _tanstack_react_query.UseQueryResult<AssignmentWithId | null, Error>;
|
|
68
|
+
|
|
69
|
+
type FsClient = ReturnType<typeof createFsClient>;
|
|
70
|
+
declare function createFsClient(db: FirebaseInstance, platform: 'web' | 'native'): Promise<{
|
|
71
|
+
assignmentRepo: {
|
|
72
|
+
get(id: string): Promise<AssignmentWithId | null>;
|
|
73
|
+
list(): Promise<AssignmentWithId[]>;
|
|
74
|
+
};
|
|
75
|
+
}>;
|
|
76
|
+
|
|
77
|
+
interface FsContext {
|
|
78
|
+
fs: Awaited<FsClient>;
|
|
79
|
+
queryClient: QueryClient;
|
|
80
|
+
}
|
|
81
|
+
declare const FsCtx: React.Context<FsContext | null>;
|
|
82
|
+
declare function SpeakableProvider({ db, platform, children, queryClient, }: {
|
|
83
|
+
db: FirebaseInstance;
|
|
84
|
+
platform: 'web' | 'native';
|
|
85
|
+
children: React.ReactNode;
|
|
86
|
+
queryClient: QueryClient;
|
|
87
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
88
|
+
declare function useFs(): FsContext;
|
|
89
|
+
|
|
90
|
+
export { type Assignment, type AssignmentAnalyticsType, type AssignmentWithId, type FsClient, FsCtx, SpeakableProvider, assignmentQueryKeys, createAssignmentRepo, createFsClient, useAssignment, useFs };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
5
|
+
import * as firebase_firestore from 'firebase/firestore';
|
|
6
|
+
import { Firestore } from 'firebase/firestore';
|
|
7
|
+
import { FirebaseFirestoreTypes } from '@react-native-firebase/firestore';
|
|
8
|
+
|
|
9
|
+
interface AssignmentWithId extends Assignment {
|
|
10
|
+
ltiLineItemId: null;
|
|
11
|
+
id: string;
|
|
12
|
+
}
|
|
13
|
+
interface Assignment {
|
|
14
|
+
name: string;
|
|
15
|
+
scheduledTime: string | null;
|
|
16
|
+
dueTime?: {
|
|
17
|
+
hours: number;
|
|
18
|
+
minutes: number;
|
|
19
|
+
nanos: number;
|
|
20
|
+
};
|
|
21
|
+
speakableio: boolean;
|
|
22
|
+
owners: string[];
|
|
23
|
+
image: {
|
|
24
|
+
path: string | null;
|
|
25
|
+
url: string;
|
|
26
|
+
};
|
|
27
|
+
dueDate: {
|
|
28
|
+
day: number;
|
|
29
|
+
month: number;
|
|
30
|
+
year: number;
|
|
31
|
+
};
|
|
32
|
+
teacherName: string;
|
|
33
|
+
courseWorkId: string | null;
|
|
34
|
+
dueDateTimestamp: {
|
|
35
|
+
seconds: number;
|
|
36
|
+
nanoseconds: number;
|
|
37
|
+
};
|
|
38
|
+
scheduledTimeTimestamp: number;
|
|
39
|
+
active: boolean;
|
|
40
|
+
voice: string | null;
|
|
41
|
+
setId: string;
|
|
42
|
+
dateMade: {
|
|
43
|
+
seconds: number;
|
|
44
|
+
nanoseconds: number;
|
|
45
|
+
};
|
|
46
|
+
maxPoints: number;
|
|
47
|
+
courseId: string;
|
|
48
|
+
isAssessment: boolean;
|
|
49
|
+
isAvailable: boolean;
|
|
50
|
+
}
|
|
51
|
+
type AssignmentAnalyticsType = 'macro' | 'gradebook' | 'cards' | 'student' | 'student_summary';
|
|
52
|
+
|
|
53
|
+
type FirebaseInstance = FirebaseFirestoreTypes.Module | Firestore;
|
|
54
|
+
type FirestoreDB = Firestore;
|
|
55
|
+
type FirestoreHelpers = typeof firebase_firestore;
|
|
56
|
+
|
|
57
|
+
declare const createAssignmentRepo: (db: FirestoreDB, h: FirestoreHelpers) => {
|
|
58
|
+
get(id: string): Promise<AssignmentWithId | null>;
|
|
59
|
+
list(): Promise<AssignmentWithId[]>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
declare const assignmentQueryKeys: {
|
|
63
|
+
all: readonly ["assignments"];
|
|
64
|
+
byId: (id: string) => readonly ["assignments", string];
|
|
65
|
+
list: () => readonly ["assignments", "list"];
|
|
66
|
+
};
|
|
67
|
+
declare function useAssignment(id: string): _tanstack_react_query.UseQueryResult<AssignmentWithId | null, Error>;
|
|
68
|
+
|
|
69
|
+
type FsClient = ReturnType<typeof createFsClient>;
|
|
70
|
+
declare function createFsClient(db: FirebaseInstance, platform: 'web' | 'native'): Promise<{
|
|
71
|
+
assignmentRepo: {
|
|
72
|
+
get(id: string): Promise<AssignmentWithId | null>;
|
|
73
|
+
list(): Promise<AssignmentWithId[]>;
|
|
74
|
+
};
|
|
75
|
+
}>;
|
|
76
|
+
|
|
77
|
+
interface FsContext {
|
|
78
|
+
fs: Awaited<FsClient>;
|
|
79
|
+
queryClient: QueryClient;
|
|
80
|
+
}
|
|
81
|
+
declare const FsCtx: React.Context<FsContext | null>;
|
|
82
|
+
declare function SpeakableProvider({ db, platform, children, queryClient, }: {
|
|
83
|
+
db: FirebaseInstance;
|
|
84
|
+
platform: 'web' | 'native';
|
|
85
|
+
children: React.ReactNode;
|
|
86
|
+
queryClient: QueryClient;
|
|
87
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
88
|
+
declare function useFs(): FsContext;
|
|
89
|
+
|
|
90
|
+
export { type Assignment, type AssignmentAnalyticsType, type AssignmentWithId, type FsClient, FsCtx, SpeakableProvider, assignmentQueryKeys, createAssignmentRepo, createFsClient, useAssignment, useFs };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// src/providers/SpeakableProvider.tsx
|
|
2
|
+
var _react = require('react');
|
|
3
|
+
|
|
4
|
+
// src/domains/assignment/assignment.repo.ts
|
|
5
|
+
var createAssignmentRepo = (db, h) => {
|
|
6
|
+
const { doc, collection, getDoc, getDocs } = h;
|
|
7
|
+
return {
|
|
8
|
+
async get(id) {
|
|
9
|
+
const snap = await getDoc(doc(db, `assignments/${id}`));
|
|
10
|
+
if (!snap.exists()) return null;
|
|
11
|
+
const data = snap.data();
|
|
12
|
+
return { id, ...data };
|
|
13
|
+
},
|
|
14
|
+
async list() {
|
|
15
|
+
const col = collection(db, "assignments");
|
|
16
|
+
const snap = await getDocs(col);
|
|
17
|
+
return snap.docs.map((d) => ({ id: d.id, ...d.data() }));
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/domains/assignment/hooks.ts
|
|
23
|
+
var _reactquery = require('@tanstack/react-query');
|
|
24
|
+
var assignmentQueryKeys = {
|
|
25
|
+
all: ["assignments"],
|
|
26
|
+
byId: (id) => [...assignmentQueryKeys.all, id],
|
|
27
|
+
list: () => [...assignmentQueryKeys.all, "list"]
|
|
28
|
+
};
|
|
29
|
+
function useAssignment(id) {
|
|
30
|
+
const { fs } = useFs();
|
|
31
|
+
return _reactquery.useQuery.call(void 0, {
|
|
32
|
+
queryKey: assignmentQueryKeys.byId(id),
|
|
33
|
+
queryFn: () => fs.assignmentRepo.get(id)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/lib/create-firebase-client.ts
|
|
38
|
+
async function createFsClient(db, platform) {
|
|
39
|
+
const dbAsFirestore = db;
|
|
40
|
+
const helpers = platform === "web" ? await Promise.resolve().then(() => _interopRequireWildcard(require("firebase/firestore"))) : await Promise.resolve().then(() => _interopRequireWildcard(require("@react-native-firebase/firestore")));
|
|
41
|
+
return {
|
|
42
|
+
assignmentRepo: createAssignmentRepo(dbAsFirestore, helpers)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/providers/SpeakableProvider.tsx
|
|
47
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
48
|
+
var FsCtx = _react.createContext.call(void 0, null);
|
|
49
|
+
function SpeakableProvider({
|
|
50
|
+
db,
|
|
51
|
+
platform,
|
|
52
|
+
children,
|
|
53
|
+
queryClient
|
|
54
|
+
}) {
|
|
55
|
+
const [fs, setFs] = _react.useState.call(void 0, null);
|
|
56
|
+
_react.useEffect.call(void 0, () => {
|
|
57
|
+
createFsClient(db, platform).then((repos) => {
|
|
58
|
+
setFs(repos);
|
|
59
|
+
});
|
|
60
|
+
}, [db, platform]);
|
|
61
|
+
if (!fs) return null;
|
|
62
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
63
|
+
FsCtx.Provider,
|
|
64
|
+
{
|
|
65
|
+
value: {
|
|
66
|
+
fs,
|
|
67
|
+
queryClient
|
|
68
|
+
},
|
|
69
|
+
children
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
function useFs() {
|
|
74
|
+
const ctx = _react.useContext.call(void 0, FsCtx);
|
|
75
|
+
if (!ctx) throw new Error("useFs must be used within a SpeakableProvider");
|
|
76
|
+
return ctx;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
exports.FsCtx = FsCtx; exports.SpeakableProvider = SpeakableProvider; exports.assignmentQueryKeys = assignmentQueryKeys; exports.createAssignmentRepo = createAssignmentRepo; exports.createFsClient = createFsClient; exports.useAssignment = useAssignment; exports.useFs = useFs;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/providers/SpeakableProvider.tsx
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
+
|
|
4
|
+
// src/domains/assignment/assignment.repo.ts
|
|
5
|
+
var createAssignmentRepo = (db, h) => {
|
|
6
|
+
const { doc, collection, getDoc, getDocs } = h;
|
|
7
|
+
return {
|
|
8
|
+
async get(id) {
|
|
9
|
+
const snap = await getDoc(doc(db, `assignments/${id}`));
|
|
10
|
+
if (!snap.exists()) return null;
|
|
11
|
+
const data = snap.data();
|
|
12
|
+
return { id, ...data };
|
|
13
|
+
},
|
|
14
|
+
async list() {
|
|
15
|
+
const col = collection(db, "assignments");
|
|
16
|
+
const snap = await getDocs(col);
|
|
17
|
+
return snap.docs.map((d) => ({ id: d.id, ...d.data() }));
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/domains/assignment/hooks.ts
|
|
23
|
+
import { useQuery } from "@tanstack/react-query";
|
|
24
|
+
var assignmentQueryKeys = {
|
|
25
|
+
all: ["assignments"],
|
|
26
|
+
byId: (id) => [...assignmentQueryKeys.all, id],
|
|
27
|
+
list: () => [...assignmentQueryKeys.all, "list"]
|
|
28
|
+
};
|
|
29
|
+
function useAssignment(id) {
|
|
30
|
+
const { fs } = useFs();
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: assignmentQueryKeys.byId(id),
|
|
33
|
+
queryFn: () => fs.assignmentRepo.get(id)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/lib/create-firebase-client.ts
|
|
38
|
+
async function createFsClient(db, platform) {
|
|
39
|
+
const dbAsFirestore = db;
|
|
40
|
+
const helpers = platform === "web" ? await import("firebase/firestore") : await import("@react-native-firebase/firestore");
|
|
41
|
+
return {
|
|
42
|
+
assignmentRepo: createAssignmentRepo(dbAsFirestore, helpers)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/providers/SpeakableProvider.tsx
|
|
47
|
+
import { jsx } from "react/jsx-runtime";
|
|
48
|
+
var FsCtx = createContext(null);
|
|
49
|
+
function SpeakableProvider({
|
|
50
|
+
db,
|
|
51
|
+
platform,
|
|
52
|
+
children,
|
|
53
|
+
queryClient
|
|
54
|
+
}) {
|
|
55
|
+
const [fs, setFs] = useState(null);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
createFsClient(db, platform).then((repos) => {
|
|
58
|
+
setFs(repos);
|
|
59
|
+
});
|
|
60
|
+
}, [db, platform]);
|
|
61
|
+
if (!fs) return null;
|
|
62
|
+
return /* @__PURE__ */ jsx(
|
|
63
|
+
FsCtx.Provider,
|
|
64
|
+
{
|
|
65
|
+
value: {
|
|
66
|
+
fs,
|
|
67
|
+
queryClient
|
|
68
|
+
},
|
|
69
|
+
children
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
function useFs() {
|
|
74
|
+
const ctx = useContext(FsCtx);
|
|
75
|
+
if (!ctx) throw new Error("useFs must be used within a SpeakableProvider");
|
|
76
|
+
return ctx;
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
FsCtx,
|
|
80
|
+
SpeakableProvider,
|
|
81
|
+
assignmentQueryKeys,
|
|
82
|
+
createAssignmentRepo,
|
|
83
|
+
createFsClient,
|
|
84
|
+
useAssignment,
|
|
85
|
+
useFs
|
|
86
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@speakableio/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/Speakable-io/speakable-core.git"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.cjs",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"react": "^18.2.0",
|
|
12
|
+
"@types/react": "^18",
|
|
13
|
+
"@react-native-firebase/firestore": ">=21",
|
|
14
|
+
"@types/firebase": "^3.2.1",
|
|
15
|
+
"firebase": "^10.1.0",
|
|
16
|
+
"tsup": "^8.0.0",
|
|
17
|
+
"typescript": "^5.5.0",
|
|
18
|
+
"vitest": "^1.5.0",
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^7.10.0",
|
|
20
|
+
"@typescript-eslint/parser": "^7.10.0",
|
|
21
|
+
"@vercel/style-guide": "^6.0.0",
|
|
22
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
23
|
+
"eslint": "8.57.0",
|
|
24
|
+
"eslint-config-prettier": "^9.1.0",
|
|
25
|
+
"eslint-plugin-import": "^2.29.1",
|
|
26
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
27
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
28
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
29
|
+
"prettier": "^3.2.5"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=18",
|
|
33
|
+
"firebase": "^10.1.0",
|
|
34
|
+
"@react-native-firebase/app": ">=21",
|
|
35
|
+
"@react-native-firebase/firestore": ">=21",
|
|
36
|
+
"@tanstack/react-query": "^5.54.1"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/Speakable-io/speakable-core/issues"
|
|
43
|
+
},
|
|
44
|
+
"description": "Shared data layer for Speakable web & mobile",
|
|
45
|
+
"files": ["dist"],
|
|
46
|
+
"homepage": "https://github.com/Speakable-io/speakable-core#readme",
|
|
47
|
+
"license": "UNLICENSED",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "restricted"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsup src/index.ts --dts --format esm,cjs --splitting",
|
|
53
|
+
"dev": "tsup src/index.ts --watch --dts --format esm,cjs --out-dir dist",
|
|
54
|
+
"test": "vitest"
|
|
55
|
+
},
|
|
56
|
+
"types": "dist/index.d.ts"
|
|
57
|
+
}
|