From af7796e1105a80ce010bb3d701883137dfb0d937 Mon Sep 17 00:00:00 2001 From: tylim Date: Sat, 30 Apr 2022 08:27:31 +0800 Subject: [PATCH 1/2] housekeeping codeForDoc --- codeForDoc/src/batch.ts | 7 +++-- codeForDoc/src/documentIdFirelord.ts | 31 ++++++++++++++----- .../src/groupCollectionQueryFirelord.ts | 12 +++++++ codeForDoc/src/init.ts | 9 +++++- codeForDoc/src/transaction.ts | 6 +++- scripts/installLatest.ts | 2 +- 6 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 codeForDoc/src/groupCollectionQueryFirelord.ts diff --git a/codeForDoc/src/batch.ts b/codeForDoc/src/batch.ts index c145c81..506727f 100644 --- a/codeForDoc/src/batch.ts +++ b/codeForDoc/src/batch.ts @@ -1,7 +1,10 @@ -import { example } from './init' +import { example, db } from './init' import { writeBatch, serverTimestamp } from 'firelordjs' -const batch = writeBatch() +const batch = writeBatch(db) +// OR +const batch_Alt = writeBatch() + export const dummy = async () => { batch.set(example.doc('hij'), { a: 6, diff --git a/codeForDoc/src/documentIdFirelord.ts b/codeForDoc/src/documentIdFirelord.ts index da8eaa3..d629712 100644 --- a/codeForDoc/src/documentIdFirelord.ts +++ b/codeForDoc/src/documentIdFirelord.ts @@ -1,12 +1,29 @@ -import { MetaTypeCreator, getFirelord, query, where } from 'firelordjs' +import { MetaTypeCreator, getFirelord } from 'firelordjs' -const firelord = getFirelord() - -type abc = MetaTypeCreator< +type Parent = MetaTypeCreator< { - a: { b: number; c: number } - d: number + a: 1 }, - 'abc', + 'a', string > +const firelordParent = getFirelord() +const ParentCollectionGroupQuery = firelordParent('a').collectionGroup() + +type Child = MetaTypeCreator< + { + a: 1 + }, + 'b', + string, + Parent +> +const firelordChild = getFirelord() + +const ChildCollectionGroupQuery = firelordChild( + 'a/putAnyStringHere/b' +).collectionGroup() + +const a = [1, 2, 3].forEach(i => { + exports[i] +}) diff --git a/codeForDoc/src/groupCollectionQueryFirelord.ts b/codeForDoc/src/groupCollectionQueryFirelord.ts new file mode 100644 index 0000000..da8eaa3 --- /dev/null +++ b/codeForDoc/src/groupCollectionQueryFirelord.ts @@ -0,0 +1,12 @@ +import { MetaTypeCreator, getFirelord, query, where } from 'firelordjs' + +const firelord = getFirelord() + +type abc = MetaTypeCreator< + { + a: { b: number; c: number } + d: number + }, + 'abc', + string +> diff --git a/codeForDoc/src/init.ts b/codeForDoc/src/init.ts index 65e8a01..6a77299 100644 --- a/codeForDoc/src/init.ts +++ b/codeForDoc/src/init.ts @@ -1,6 +1,7 @@ import { getFirelord } from 'firelordjs' import { initializeApp } from 'firebase/app' import { Example } from './dataType' +import { getFirestore } from 'firebase/firestore' initializeApp({ apiKey: '### FIREBASE API KEY ###', @@ -8,4 +9,10 @@ initializeApp({ projectId: '### CLOUD FIRESTORE PROJECT ID ###', }) -export const example = getFirelord()('SomeCollectionName') +export const db = getFirestore() + +const firelordExample = getFirelord(db) +// OR +const firelordExample_Alt = getFirelord() + +export const example = firelordExample('SomeCollectionName') diff --git a/codeForDoc/src/transaction.ts b/codeForDoc/src/transaction.ts index 60a3948..887e5c1 100644 --- a/codeForDoc/src/transaction.ts +++ b/codeForDoc/src/transaction.ts @@ -1,4 +1,4 @@ -import { example } from './init' +import { example, db } from './init' import { runTransaction, serverTimestamp, @@ -8,6 +8,10 @@ import { export const dummy = async () => { try { + await runTransaction(db, async transaction => { + // ... + }) + // OR you can skip 'db' await runTransaction(async transaction => { await transaction.get(example.doc('lmn')).then(docSnapshot => { const data = docSnapshot.data() diff --git a/scripts/installLatest.ts b/scripts/installLatest.ts index bb0a898..861035c 100644 --- a/scripts/installLatest.ts +++ b/scripts/installLatest.ts @@ -2,5 +2,5 @@ import pkg from '../package.json' import shell from 'shelljs' // https://stackoverflow.com/questions/38032047/how-to-execute-npm-run-command-programmatically -// to make sure it always install the latest exact version because apparently `latest` is not working in package.json with just published package +// this code is for newly published code testing because @latest apparently not alway able to target newly published package shell.exec(`npm --prefix codeForDoc i ${pkg.name}@${pkg.version}`) From 4fc44b97dfbee652b47e9c31a86ce47eb4fe30c4 Mon Sep 17 00:00:00 2001 From: tylim Date: Sun, 1 May 2022 03:31:07 +0800 Subject: [PATCH 2/2] housekeeping --- .opensource/project.json | 8 +++++++- package.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.opensource/project.json b/.opensource/project.json index f2a81e5..0193cf3 100644 --- a/.opensource/project.json +++ b/.opensource/project.json @@ -7,7 +7,13 @@ "pages": [], - "related": ["tylim88/Firelordrn", "tylim88/Firelord"], + "related": [ + "tylim88/Firelordrn", + "tylim88/Firelord", + "tylim88/FireLaw", + "tylim88/FireCall", + "tylim88/FireCaller" + ], "tabs": [] } diff --git a/package.json b/package.json index 244a9e2..dd8ea3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "firelordjs", - "version": "1.1.17", + "version": "1.1.18", "description": "🔥 Extremely High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience", "source": "src/index.ts", "main": "dist/src/index.js",