投稿時間:2023-04-16 19:10:19 RSSフィード2023-04-16 19:00 分まとめ(11件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
TECH Techable(テッカブル) 生徒はアバターで通学⁉メタバース構築・エンジニアリングなどが学べる「メタバースカレッジ」 https://techable.jp/archives/203421 codrea 2023-04-16 09:00:16
python Pythonタグが付けられた新着投稿 - Qiita DollyV2にインストラクションを提示して使ってみる(1) https://qiita.com/tomofu74/items/a653faed4096187cbe4f dolly 2023-04-16 18:16:15
Linux Ubuntuタグが付けられた新着投稿 - Qiita Ubuntu22.04+Perl+Selenium+Chromeでスクレイピング https://qiita.com/jiey@github/items/c85cff47bea8524aef27 chromedrivergooglechrome 2023-04-16 18:02:44
AWS AWSタグが付けられた新着投稿 - Qiita AWS VPC関連の復習 https://qiita.com/FujiRyo/items/6fbdc229db116cd2dbea awsvpc 2023-04-16 18:54:37
海外TECH DEV Community JS - Map & Symbol object https://dev.to/jiiincho/js-map-symbol-object-5b5d JS Map amp Symbol objectHere is my initial failed LeetCode answer for Memoize II function memoize fn let previousParameters let cachedResult return function params if params and previousParameters array are deep equal use cached result const isEqual isDeepEqual params previousParameters if isEqual return cachedResult else update previousParameters call fn params assign result previousParameters params slice cachedResult fn params return cachedResult const isDeepEqual object object gt const objKeys Object keys object const objKeys Object keys object if objKeys length objKeys length return false for var key of objKeys const value object key const value object key const isObjects isObject value amp amp isObject value if isObjects amp amp isDeepEqual value value isObjects amp amp value value return false return true const isObject object gt return object null amp amp typeof object object isDeepEqual was a method that I normally use in my practice But this solution fails to differentiate unique parameters Because previousParameters is a shallow copy of given param it creates new reference o o will always differ from next o o After couple of failures I had to glanced a few solutions and got a hint that Map object was right way to go Unfortunately I have no idea what javascript Map object or Hash Map data structure is To begin with what is data structure Data structure DS is a way of organising data so that it can be accessed queried updated quickly and easilyThere is a related concept called Abstract Data Types ADT Abstract Data Types vs Data StructureAbstract Data Type ADT provides the interface Interface does not give any specific details or in what programming languageHow Data Structure behave amp what method this data structure have is ADTAbstraction ADT Implementation DS ListDynamic Array Linked ListQueueLinked List based Queue Array based Queue Stack based QueueMapTree Map Hash Map Hash Table here is our map Here I made the second mistake that I simply assigned param as key value let localCache new Map if localCache has params localCache set params fn params return localCache get params This solution failed because params in localCache has params method does not compare individual values in params array For example const foo and const bar foo and bar has different reference therefor it is always unique Which implies that Map object is a perfect data structure when a value paired to a single key In other words to use Map object correctly I need to create nested Map object from to But this approach has one challenge that get method will return a branch instead of result For example fn cache get will return which is branch not the result To solve it we need a unique key to mark the value as result a local variable that stores the last child map object in nested map so we can extract the result value by get method Here is final solution const RES Symbol result a unique key return function params let localCache new Map a local variable for let param of params if localCache has param localCache set param new Map localCache localCache get param if localCache has RES assign function result in last child localCache set RES fn params return localCache get RES This question was really great to understand the usage of Map object Faster querying 2023-04-16 09:21:34
海外TECH DEV Community How to Build a Fully Functional ToDo SaaS Using Next.js and ZenStack's Access Control Policy https://dev.to/zenstack/how-to-build-a-fully-functional-todo-saas-using-nextjs-and-zenstacks-access-control-policy-408p How to Build a Fully Functional ToDo SaaS Using Next js and ZenStack x s Access Control PolicyAlmost all the SaaS now is collaborative from the originator Salesforce to the newly emerging one like Notion To make it collaborative technically we need to build the foundation to support tenant isolation with an access control policy A classic challenge here is striking a balance between app security and dev productivity ZenStack s access policy provides an innovative way to achieve that balance using the declarative schema PrerequisiteThis article is the second part of the tutorial on building the app from scratch It is assumed that you have read the first part of it to build the SaaS team space below How to build a collaborative SaaS product using Next js and ZenStack s access control policy JS for ZenStack・Feb ・ min read webdev nextjs tutorial javascript So it will continue from there to adding the ToDo functionality below Create Delete a Todo list either public or private Public means others in the same team space could see it Create Delete Complete a Todo under a Todo list Define schema RelationsWe will add two new models List and Todo The relationship between them and the existing Space is One to many relation like below The model definitions would be like below model List id String id default uuid createdAt DateTime default now updatedAt DateTime updatedAt space Space relation fields spaceId references id onDelete Cascade spaceId String owner User relation fields ownerId references id onDelete Cascade ownerId String title String length whether it is private private Boolean default false todos Todo model Todo id String id default uuid createdAt DateTime default now updatedAt DateTime updatedAt owner User relation fields ownerId references id onDelete Cascade ownerId String list List relation fields listId references id onDelete Cascade listId String title String length completed time completedAt DateTime Then we should also add the reversed relation fields in User and Spacemodel User lists List todos Todo model Space lists List Access PolicyDo you still remember how did we achieve tenant isolation using Collection Predicate Expression If not please take this chance to review it quickly because that s the foundation here Listmodel List require login deny all auth null can be read by owner or space members only if not private allow read owner auth space members user auth amp amp private when create owner must be set to current user and user must be in the space allow create owner auth amp amp space members user auth when create owner must be set to current user and user must be in the space update is not allowed to change owner allow update owner auth amp amp space members user auth amp amp future owner owner can be deleted by owner allow delete owner auth You can see space members user auth almost appears in every rule For the same example I used in the first article It checks that if Auth is in the same space as Bob Have you noticed there is a new future used in the update rule This is used to do the post update check By default in the update rule all the fields referenced in the expression refer to the “pre state However in some cases we want to restrict the “post state As in this example we want to ensure that an update cannot alter its owner Todomodel Todo require login deny all auth null owner has full access also space members have full access if the parent List is not private allow all list owner auth allow all list space members user auth amp amp list private update cannot change owner deny update future owner owner There should have nothing new for you now Now let s run the below command to flush the change to the Prisma schema and database npx zenstack generate amp amp npx prisma db pushCongratulations With ZenStack once the schema is completed the majority of the backend work is already completed freeing up your time to concentrate on the front end work Todo ListLet s create the Todo list component under src components TodoList tsx import LockClosedIcon TrashIcon from heroicons react outline import useList from lib hooks import List from prisma client import customAlphabet from nanoid import User from next auth import Image from next image import Link from next link import useRouter from next router import Avatar from Avatar import TimeInfo from TimeInfo type Props value List amp owner User deleted value List gt void export default function TodoList value deleted Props const router useRouter const del useList const deleteList async gt if confirm Are you sure to delete this list await del where id value id if deleted deleted value html return Then let s show the Todo list in the space home page under src pages space slug index tsx import SpaceContext UserContext from lib context import useList from lib hooks import List Space User from prisma client import BreadCrumb from components BreadCrumb import SpaceMembers from components SpaceMembers import TodoList from components TodoList import WithNavBar from components WithNavBar import GetServerSideProps from next import useRouter from next router import ChangeEvent FormEvent useContext useEffect useRef useState from react import toast from react toastify import getEnhancedPrisma from server enhanced db function CreateDialog created created list List gt void type Props space Space lists List amp owner User export default function SpaceHome props Props const router useRouter const findMany useList const data lists mutate refetch findMany where space slug router query slug as string include owner true orderBy updatedAt desc disabled router query slug initialData props lists html return export const getServerSideProps GetServerSideProps lt Props gt async req res params gt const db await getEnhancedPrisma req res const space await db space findUnique where slug params slug as string if space return notFound true const lists await db list findMany where space slug params slug as string include owner true orderBy updatedAt desc return props space lists Same as before when calling findMany to get all the Todo lists that could be seen by the current user either in auto generated hooks or getServerSideProps the only filter you need to specify is the space slug which is because one user could belong to multiple spaces You don t need to worry about whether a Todo list is created by a current user or is public to be seen You just write the simple query and let ZenStack take care of it based on the access policy defined in the schema Let s still use the ZenStack team space to do the little test Let s create two Todo lists public and private each by admin Then from Bob s account it could only see the public one TodoLet s create the Todo component under src components Todo tsx import TrashIcon from heroicons react outline import useTodo from lib hooks import Todo User from prisma client import ChangeEvent from react import Avatar from Avatar import TimeInfo from TimeInfo type Props value Todo amp owner User updated value Todo gt any deleted value Todo gt any export default function TodoComponent value updated deleted Props const update del useTodo const deleteTodo async gt await del where id value id if deleted deleted value const toggleCompleted async completed boolean gt if completed value completedAt return const newValue await update where id value id data completedAt completed new Date null if updated amp amp newValue updated newValue html return Then let s add a new page for a Todo list to show all the Todos under src pages space slug listId index tsx import PlusIcon from heroicons react outline import useCurrentUser from lib context import useTodo from lib hooks import List Space Todo User from prisma client import BreadCrumb from components BreadCrumb import TodoComponent from components Todo import WithNavBar from components WithNavBar import GetServerSideProps from next import ChangeEvent KeyboardEvent useState from react import toast from react toastify import getEnhancedPrisma from server enhanced db type Props space Space list List todos Todo amp owner User export default function TodoList props Props const user useCurrentUser const title setTitle useState const findMany create useTodo const data todos mutate refetch findMany where listId props list id include owner true orderBy updatedAt desc initialData props todos disabled props list const createTodo async gt try const todo await create data title owner connect id user id list connect id props list id console log Todo created todo setTitle refetch catch err any toast error Failed to create todo err info message err message if props space props list return lt gt lt gt html return export const getServerSideProps GetServerSideProps lt Props gt async req res params gt const db await getEnhancedPrisma req res const space await db space findUnique where slug params slug as string if space return notFound true const list await db list findUnique where id params listId as string if list return notFound true const todos await db todo findMany where listId params listId as string include owner true orderBy updatedAt desc return props space list todos All done Then you can enjoy collaborating in the team space now Requirement ChangeNow we could only see the public Todo list in the space Let s say we would like to change it so that all the Todo lists could be seen But for the private list the todo under it could only be seen by its owner How many places do you think we need to change Actually just one in the List model That s the beauty of ZenStack occasionally achieving your desired result can be simply modifying the schema file without requiring any changes to the JS TS code ConclusionI hope this tutorial can show you the benefit of ZenStack in using the data model as the single source of truth to handle access control Feel free to contact us on our Discord or GitHub if you have any questions about it 2023-04-16 09:10:36
海外TECH CodeProject Latest Articles Web Search Engine https://www.codeproject.com/Articles/5319612/Web-Search-Engine mining 2023-04-16 09:37:00
海外ニュース Japan Times latest articles Suspect may have used homemade pipe bomb in Kishida attack, investigators say https://www.japantimes.co.jp/news/2023/04/16/national/kishida-explosion-investigation/ hyogo 2023-04-16 18:37:10
ニュース BBC News - Home Nurses' strikes could continue till Christmas, warns RCN union leader https://www.bbc.co.uk/news/health-65291267?at_medium=RSS&at_campaign=KARANGA weeks 2023-04-16 09:40:36
ニュース BBC News - Home Dubai fire: Sixteen killed in blaze at Al Ras apartment building https://www.bbc.co.uk/news/world-middle-east-65290956?at_medium=RSS&at_campaign=KARANGA compliance 2023-04-16 09:45:35
IT 週刊アスキー 【パンチョ】やみつきこってり♡ 鮭ソテーまるごと×圧倒的バター感の「鮭ときのこのバター醤油スパ」新登場 https://weekly.ascii.jp/elem/000/004/132/4132363/ 期間限定 2023-04-16 18:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)